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

Declare CLI options as global #215

Closed
theredfish opened this issue May 25, 2022 · 5 comments
Closed

Declare CLI options as global #215

theredfish opened this issue May 25, 2022 · 5 comments
Assignees
Labels
enhancement Improvement of existing features or bugfix
Milestone

Comments

@theredfish
Copy link
Contributor

theredfish commented May 25, 2022

I'm working with the CustomCli and I use cargo aliases. It would be handy to have the default cli options declared as global so we can access them via the subcommands directly.

I created a draft example here. I introduced a subcommand smoke and changed the options to be global.

You can run the test cli like this :

  • Without global option : cargo test --package cucumber --test cli -- smoke --report-name "test"
  • With the fail-fast global option : cargo test --package cucumber --test cli -- smoke --report-name "test" --fail-fast

Seems to work correctly. Do you think it's ok? Maybe there are some side effects I didn't think about. Maybe there is a better way to handle this need?

@tyranron tyranron added the enhancement Improvement of existing features or bugfix label May 25, 2022
@tyranron
Copy link
Member

@theredfish seems like a reasonable improvement. Would be nice to see this as a separate PR.

@ilslv it seems that it won't break anything. Could you confirm this?

@ilslv
Copy link
Member

ilslv commented May 25, 2022

@theredfish I'm concerned that this can lead to the issue described in clap-rs/clap#3721. Is this the only way to let users have subcommands and provide cucumber default cli options? Doesn't cargo test --package cucumber --test cli -- --fail-fast smoke --report-name "test" work without global options now?

@theredfish
Copy link
Contributor Author

theredfish commented May 25, 2022

I'm not sure to see exactly what's the issue with the design even after reading the explanations? Isn't it intended to have global options accessible with or without the subcommand?

cargo test --package cucumber --test cli -- --fail-fast smoke --report-name "test" works perfectly indeed. But when you use cargo aliases for example, let's say smoke, then you don't have access to the base options since you're already in the subcommand part.

Ex of toml file with aliases (it doesn't reflect a real alias case but I kept the same command I used in the discussion) :

[alias]
smoke = "test --package cucumber --test cli -- smoke"

then if the options are not global, you can't access for example the --fail-fast flag. Ideally I would like to use it like this with the alias :

cargo smoke --report-name "test" --fail-fast

Hope it makes sense regarding the need. But I can understand the concerns if there are some risks of clashes. But I'm not sure to see how it's a bad design to have global options with required commands.

@tyranron
Copy link
Member

@ilslv

I'm concerned that this can lead to the issue described in clap-rs/clap#3721.

Well, users still can hit this issue by providing custom global CLI options along with custom subcommands. I don't see this being a critical one.

@ilslv
Copy link
Member

ilslv commented May 25, 2022

@theredfish thanks for a more detailed explanation! After reading it, seems like described issue shouldn't affect any users ever (and even if it does, it's just a help message after all), so I'm in favor of this feature being implemented.

tyranron added a commit that referenced this issue May 26, 2022
- describe Cargo aliases in Book

Co-authored-by: Kai Ren <tyranron@gmail.com>
@tyranron tyranron added this to the 0.14.0 milestone May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existing features or bugfix
Projects
None yet
Development

No branches or pull requests

3 participants