Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

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
wants to merge 2 commits into from
Closed

Conversation

peterrehm
Copy link
Contributor

@peterrehm peterrehm commented May 25, 2016

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.

$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.

@carsonbot carsonbot added Status: Needs Review Console DX DX = Developer eXperience (anything that improves the experience of using Symfony) Bug labels May 25, 2016
@stof
Copy link
Member

stof commented May 25, 2016

Please add a test covering this to prevent regressions

@stof
Copy link
Member

stof commented May 25, 2016

btw, it may even go into 2.3 (if it is merged in the next few days)

@peterrehm
Copy link
Contributor Author

@stof Test just has been added.


$application->run($input, $output);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the trailing spaces here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@xabbuh
Copy link
Member

xabbuh commented May 25, 2016

👍 apart from my minor comment

Status: Reviewed

@fabpot
Copy link
Member

fabpot commented May 26, 2016

Thank you @peterrehm.

fabpot added a commit that referenced this pull request 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 May 26, 2016
@fabpot fabpot mentioned this pull request May 26, 2016
@peterrehm peterrehm deleted the console-command branch May 26, 2016 18:08
@fabpot fabpot mentioned this pull request May 30, 2016
This was referenced Jun 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Console DX DX = Developer eXperience (anything that improves the experience of using Symfony) Status: Reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.