8000 [Console] Support empty values for options · Issue #21215 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Support empty values for options #21215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
javiereguiluz opened this issue Jan 9, 2017 · 7 comments
Closed

[Console] Support empty values for options #21215

javiereguiluz opened this issue Jan 9, 2017 · 7 comments

Comments

@javiereguiluz
Copy link
Member
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 2.7

Fabien added this comment about this bug:

#20044 this is a bug on Console that should be fixed, when passing --prefix="", the prefix should be empty.

@chalasr
Copy link
Member
chalasr commented Jan 10, 2017

@fabpot Ok that passing --prefix="" or --prefix "" should give an empty prefix, but when passing --prefix without explicit value, how should it behave (take the default value like when don't specifying the option at all, or be empty)? Imho it should be empty too, --prefix and --prefix "" are the same to me (and for ArgvInput too btw).

@chalasr
Copy link
Member
chalasr commented Jan 10, 2017

See #21228

@javiereguiluz
Copy link
Member Author

Closing it as "impossible to fix" ... documenting this behavior in symfony/symfony-docs#7363

@chalasr
Copy link
Member
chalasr commented Jan 14, 2017

Well, solving the issue of having empty strings when quotes are specified involves to loose null values when it make sense thus cannot be solved without refactoring and breaking BC.
However #21228 fixes a real issue about the impossibility to know if an option was set without/with an empty value, which is I think what @fabpot meant at first.

Think about our first issue with the --prefix option, the first fix made that was reverted (#20184) would have been correct and IMHO pretty straightforward: $prefix = $input->getOption('prefix') ?: "", don't you think? Actually, you always get the default value, that is weird imho.

@chalasr
Copy link
Member
chalasr commented Jan 17, 2017

This should be reopened :)

@xabbuh xabbuh reopened this Jan 17, 2017
@dakess
Copy link
dakess commented Jan 28, 2017

I have the same problem. I tried a lot of workarounds from #11572 but nothing works as expected. however I found this and tried the patch in #21228, I can say it fixes the bug for me.
is it possible to apply #21228 on the symfony/console composer package? can I help somehow? thanks

@chalasr
Copy link
Member
chalasr commented Jan 28, 2017

@dakess Thanks for confirming that the fix is valid, it's the best help you could give.

I tried a lot of workarounds from #11572 but nothing works as expected

I was not aware of this issue, it seems to be a duplicate. Added it to #21228 fixed tickets.

is it possible to apply #21228 on the symfony/console composer package

It'll be once merged, then automatically available in next releases.
I'm waiting for a decision to be made but I don't see any blocker since it is a really annoying bug that should be fixed, as stated by the symfony lead.

fabpot added a commit that referenced this issue Mar 1, 2017
…empty) should remain empty (chalasr)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[Console] Explicitly passed options without value (or empty) should remain empty

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21215 #11572 #12773
| License       | MIT
| Doc PR        | n/a (maybe look at updating the existing one)

This conserves empty values for options instead of returning their default values.

Code:
```php
// cli.php
$application = new Application();
$application
    ->register('echo')
    ->addOption('prefix', null, InputOption::VALUE_OPTIONAL, null, 'my-default')
    ->addArgument('value', InputArgument::REQUIRED)
    ->setCode(function ($input, $output) {
        var_dump($input->getOption('prefix'));
    });
$application->run();
```

Before:
![before](http://image.prntscr.com/image/157d9c6c054240da8b0dce54c9ce24d6.png)

After:
![after](http://image.prntscr.com/image/4aeded77f8084d3c985687fc8cc7b54e.png)

Commits
-------

8086742 [Console] Explicitly passed options without value (or empty) should remain empty
@fabpot fabpot closed this as completed Mar 1, 2017
xabbuh added a commit to symfony/symfony-docs that referenced this issue Mar 1, 2017
…ions (javiereguiluz)

This PR was merged into the 2.7 branch.

Discussion
----------

Document that you can't pass empty strings to console options

Related to symfony/symfony#21215

Commits
-------

9666907 Document that you can't pass empty strings to console options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants
0