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

Clarify documentation regarding AppSettings and child subcommand propagation #429

Closed
andresv opened this issue Feb 18, 2016 · 8 comments
Closed
Labels
A-docs Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations

Comments

@andresv
Copy link

andresv commented Feb 18, 2016

Clap 2.1.0

Example code is here (i have not yet pushed minor tweaks needed for clap 2.x, but overall concept is the same): https://github.com/cubehub/doppler/blob/master/src/usage.rs#L153.

If negative number like -6400 is given to --shift, i get this:

> cat ~/Downloads/rtl_fm_i16_raw_48k_145864_2.iq | ./target/debug/doppler const -i i16 -o i16 -s 48000 --shift -6400 > ~/Downloads/shifted.iq
error: Found argument '-6' which wasn't expected, or isn't valid in this context
@andresv andresv changed the title Cannot give negative number as argument value Cannot take negative number as argument value Feb 18, 2016
@Vinatorul
Copy link
Contributor

Thank you for example. I am not sure, but I think negative arguments should be passed in quotes. Let's wait for the @kbknapp answer.

@andresv
Copy link
Author

andresv commented Feb 19, 2016

I tried with quotes, still no go.

@Vinatorul Vinatorul added C-bug Category: Updating dependencies C: args and removed T: RFC / question labels Feb 19, 2016
@kbknapp
Copy link
Member

kbknapp commented Feb 19, 2016

You have to use the AppSettings::AllowLeadingHyphen.

I'll leave this open until you can confirm that's working for you. 😉

@kbknapp kbknapp added T: RFC / question and removed C: args C-bug Category: Updating dependencies labels Feb 19, 2016
@andresv
Copy link
Author

andresv commented Feb 19, 2016

Basically tried with that:

let matches = App::new("doppler")
            .setting(AppSettings::AllowLeadingHyphen)
            .version(env!("CARGO_PKG_VERSION"))
            .about("Compensates IQ data stream doppler shift based on TLE information, also can be used for doing constant baseband shifting")


            .subcommand(SubCommand::with_name("const")
                .about("Constant shift mode")
                .arg(Arg::with_name("SHIFT")
                   .long("shift")
                   .help("frequency shift in Hz")
                   .required(true)
                   .takes_value(true)))

            .get_matches();

And still got:

> cat ~/Downloads/rtl_fm_i16_raw_48k_145864_2.iq | ./target/debug/doppler const -i i16 -o i16 -s 48000 --shift -5700 > ~/Downloads/shifted.iq
error: Found argument '-5' which wasn't expected, or isn't valid in this context

@Vinatorul
Copy link
Contributor

You should specify setting for subcommand, because it is also an App, like this:

let matches = App::new("doppler")
            .version(env!("CARGO_PKG_VERSION"))
            .about("Compensates IQ data stream doppler shift based on TLE information, also can be used for doing constant baseband shifting")
            .subcommand(SubCommand::with_name("const")
                .about("Constant shift mode")
                .setting(AppSettings::AllowLeadingHyphen)
                .arg(Arg::with_name("SHIFT")
                   .long("shift")
                   .help("frequency shift in Hz")
                   .required(true)
                   .takes_value(true)))

            .get_matches();

@kbknapp
Copy link
Member

kbknapp commented Feb 19, 2016

Ah ok, that's because the AppSettings only apply to the current command, and are not propagated down through child subcommands. This should be cleared up in the docs.

Edit: Oops @Vinatorul beat me to it! 😉

@kbknapp kbknapp added C-enhancement Category: Raise on the bar on expectations P4: nice to have A-docs Area: documentation, including docs.rs, readme, examples, etc... and removed T: RFC / question labels Feb 19, 2016
@andresv
Copy link
Author

andresv commented Feb 19, 2016

Very good now it works. I guess I can close it.

@andresv andresv closed this as completed Feb 19, 2016
@Vinatorul
Copy link
Contributor

@andresv thank you for response. I think it will be reclassified as documentation issue.
Negative values and subcomands are not clear enough

@Vinatorul Vinatorul reopened this Feb 19, 2016
@kbknapp kbknapp changed the title Cannot take negative number as argument value Clarify documentation regarding AppSettings and child subcommand propagation Feb 19, 2016
@kbknapp kbknapp mentioned this issue Feb 19, 2016
29 tasks
homu added a commit that referenced this issue Feb 19, 2016
Issue 421, 427, and 429

This PR adds better examples for `Arg` methods as well as

* implements support for displaying the help on the next line (#427)
* Clarifies `AppSettings` propagation rules (#429)
* Fixes failing clippy lints
* Moves github specific files to a `.github` directory

----

Copied from #421

- [x] `short`
- [x] `long`
- [x] `help`
- [x] `required`
- [x] `conflicts_with`
- [x] `conflicts_with_all`
- [x] `overrides_with`
- [x] `overrides_with_all`
- [x] `requires`
- [x] `requires_all`
- [x] `takes_value`
- [x] `index`
- [x] `multiple`
- [x] `global`
- [x] `empty_values`
- [x] `hidden`
- [x] `possible_values`
- [x] `possible_value`
- [x] `group`
- [x] `number_of_values`
- [x] `validator`
- [x] `max_values`
- [x] `min_values`
- [x] `use_delimiter`
- [x] `value_delimiter`
- [x] `value_names`
- [x] `value_name`
- [x] `default_value`
- [x] `next_line_help`
homu added a commit that referenced this issue Feb 19, 2016
Issue 421, 427, and 429

This PR adds better examples for `Arg` methods as well as

* implements support for displaying the help on the next line (#427)
* Clarifies `AppSettings` propagation rules (#429)
* Fixes failing clippy lints
* Moves github specific files to a `.github` directory

----

Copied from #421

- [x] `short`
- [x] `long`
- [x] `help`
- [x] `required`
- [x] `conflicts_with`
- [x] `conflicts_with_all`
- [x] `overrides_with`
- [x] `overrides_with_all`
- [x] `requires`
- [x] `requires_all`
- [x] `takes_value`
- [x] `index`
- [x] `multiple`
- [x] `global`
- [x] `empty_values`
- [x] `hidden`
- [x] `possible_values`
- [x] `possible_value`
- [x] `group`
- [x] `number_of_values`
- [x] `validator`
- [x] `max_values`
- [x] `min_values`
- [x] `use_delimiter`
- [x] `value_delimiter`
- [x] `value_names`
- [x] `value_name`
- [x] `default_value`
- [x] `next_line_help`
homu added a commit that referenced this issue Feb 19, 2016
Issue 421, 427, and 429

This PR adds better examples for `Arg` methods as well as

* implements support for displaying the help on the next line (#427)
* Clarifies `AppSettings` propagation rules (#429)
* Fixes failing clippy lints
* Moves github specific files to a `.github` directory

----

Copied from #421

- [x] `short`
- [x] `long`
- [x] `help`
- [x] `required`
- [x] `conflicts_with`
- [x] `conflicts_with_all`
- [x] `overrides_with`
- [x] `overrides_with_all`
- [x] `requires`
- [x] `requires_all`
- [x] `takes_value`
- [x] `index`
- [x] `multiple`
- [x] `global`
- [x] `empty_values`
- [x] `hidden`
- [x] `possible_values`
- [x] `possible_value`
- [x] `group`
- [x] `number_of_values`
- [x] `validator`
- [x] `max_values`
- [x] `min_values`
- [x] `use_delimiter`
- [x] `value_delimiter`
- [x] `value_names`
- [x] `value_name`
- [x] `default_value`
- [x] `next_line_help`
@homu homu closed this as completed in 3c8db0e Feb 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations
Projects
None yet
Development

No branches or pull requests

3 participants