Skip to content
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

tests(Mixed args): Add failing test for mixed argument types #212

Closed
wants to merge 1 commit into from
Closed

tests(Mixed args): Add failing test for mixed argument types #212

wants to merge 1 commit into from

Conversation

wezm
Copy link

@wezm wezm commented Aug 31, 2015

Not sure if I'm missing anything but this code was extracted from my project because the arguments are not being parsed as expected.

It is expected that the added test will pass by assigning the value
config.toml to the config argument and 1 to the feed argument
but it currently fails with the error:

error: The following required arguments were not supplied:
  '<config>'

USAGE:
  mixed_positional_and_options <config> --feed <feed>...

For more information try --help

It is expected that this test will pass by assigning the value
'config.toml' to the 'config' argument and '1' to the 'feed' argument
but it currently fails with the error:

    error: The following required arguments were not supplied:
      '<config>'

    USAGE:
      mixed_positional_and_options <config> --feed <feed>...

    For more information try --help
@Vinatorul
Copy link
Contributor

Thanks for finding and taking the time to do this!
Have you tried to change index for positional from 1 to 2?

@wezm
Copy link
Author

wezm commented Aug 31, 2015

Changing to index(2) gives error:

'mixed_positional_and_options' panicked at 'Found positional argument "config" who's index is 2 but there are only 1 positional arguments defined’

@Vinatorul
Copy link
Contributor

Maybe clap decided that config.toml belongs to feed, let's wait for @kbknapp answer.

@kbknapp
Copy link
Member

kbknapp commented Aug 31, 2015

The issue is because --feed is set to multiple(true); so clap doesn't know when --feed stops and config starts. The index only applies to positional arguments, not arguments as a whole because calling the above mixed_positional_and_options config.toml --feed feed works.

The fix is one of three options

  • give --feed a bound of values (i.e. one at a time, but still multiple overall by adding number_of_values(1) to --feed this will allow -f feed1 -f feed2 -f feed3)
  • use the Unix -- to denote only positional values follow (i.e. $ mixed_positional_and_options --feed feed -- config.toml)
  • Re-order the arguments at runtime (as described above), so that config comes before the multiple --feed

@wezm
Copy link
Author

wezm commented Aug 31, 2015

Thanks for the info. number_of_values(1) is the behaviour I was after. I will go with that.

@wezm wezm closed this Aug 31, 2015
@kbknapp
Copy link
Member

kbknapp commented Sep 1, 2015

Glad we could help 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants