Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Console] Unexpected unsupported command option shortcut #18856

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
nico-incubiq opened this issue May 24, 2016 · 4 comments
Closed

[Console] Unexpected unsupported command option shortcut #18856

nico-incubiq opened this issue May 24, 2016 · 4 comments

Comments

@nico-incubiq
Copy link
Contributor

nico-incubiq commented May 24, 2016

Hi,
I am using Symfony 2.8.6, and after creating a new Command, I stumbled upon an unexpected error:

An argument with name "command" already exists.
[Symfony\Component\Console\Exception\LogicException]
An argument with name "command" already exists.

After trying a lot of different solutions, I found out that the error had to do with the option shortcut I used:

$this->setName('my:super:command')
->setAliases(['my:super:commandalias'])
->setDescription('Performs some irrelevant work.')
->addOption('survey', 's', InputOption::VALUE_REQUIRED, 'My option with a shortcut.')

After changing the alias (or setting it to null), the error just stopped popping out.
Is there any obvious reason I am missing here, or is this a bug?
Because to my knowledge "s" is not used anywhere else.

Furthermore, the error is awkwardly cryptic and gave me a hard time debugging this.

Regards,
Nicolas

@mccullagh
Copy link
Contributor

It is used from the FrameworkBundle for the shell Option https://github.com/symfony/symfony/blob/2.8/src/Symfony/Bundle/FrameworkBundle/Console/Application.php#L44

The Option is removed in 3.0

@peterrehm
Copy link
Contributor

Ok, I see the point, the error is just raised when calling the command due to the duplicate alias of the Option. The error message is indeed misleading.

@peterrehm
Copy link
Contributor

I traced the issue down and just submitted a fix. #18864

@javiereguiluz javiereguiluz changed the title [Command] Unexpected unsupported option shortcut [Console] Unexpected unsupported command option shortcut May 25, 2016
@nico-incubiq
Copy link
Contributor Author

Wonderful! Thanks for the fix

fabpot added a commit that referenced this issue May 26, 2016
…uplicate option shortcut (peterrehm)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #18864).

Discussion
----------

[Console][DX] Fixed ambiguous error message when using a duplicate option shortcut

| Q             | A
| ------------- | ---
| Branch?       | 2.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18856
| License       | MIT
| Doc PR        | -

I assume this should be merged into 2.3 as per @stof's comment.

There is a race condition when you run a command which has a duplicate option shortcut. Simply changing the order so that Options are merged before the Arguments solves that race condition.

````php
$this->setName('my:super:command')
->setAliases(['my:super:commandalias'])
->setDescription('Performs some irrelevant work.')
->addOption('survey', 'e', InputOption::VALUE_REQUIRED, 'My option with a shortcut.')
````

Gives the error message:

```
  [Symfony\Component\Console\Exception\LogicException]
  An argument with name "command" already exists.
```

This happens as the first time the definition is merged happens here:

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Application.php#L820

As this throws an error here:

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Command/Command.php#L309

The commans are merged but not the options.

Merging it then again when the command is run

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Command/Command.php#L217

throws an error due to the duplicate argument as the arguments already have been merged. This time the error message is not surpressed and will confuse the user.

Changing the order should fix the issue for duplicate arguments as well as for duplicate options.

Commits
-------

7cb7655 [Console][DX] Fixed ambiguous error message when using a duplicate option shortcut
@fabpot fabpot closed this as completed May 26, 2016
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