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

unique command line arguments #1441

Closed
suhr opened this issue Mar 29, 2019 · 2 comments
Closed

unique command line arguments #1441

suhr opened this issue Mar 29, 2019 · 2 comments

Comments

@suhr
Copy link

suhr commented Mar 29, 2019

This feature request is inspired by this discussion.

Long story short: at this moment, tox-node uses the config subcommand to run a node with the configuration from a configuration file. The reason for this is because tox-node can be also run without a configuration file, with all required options passed as command line arguments. The usage of subcommand allows to avoid the situation when both configuration file and command line arguments are provides simultaneously.

The problem is, I believe that this is in no way a valid usage of subcommands. The purpose of subcommands is to provide actions, but config is not an action. So instead of config subcommand there should be the --config command line option.

At this moment, clap-rs provides no ergonomic way to specify an option that excludes all other options. This issue proposes adding a method for specifying such options.

@kbknapp
Copy link
Member

kbknapp commented Apr 5, 2019

There is quite a bit of discussion about the handling of configuration files. This is one of the main goals v3 is trying to solve.

I'm not clear on if you're currently handling the configuration files manually? If so, I would recommend the follow instead of a unique:

note: This mainly works if the number of required by default arguments is relatively low

  • Create a --mode=MODE option, which only accepts two values config|cli, and defaults to cli
  • In your required arguments use Arg::required_if to only be required if --mode=cli
  • In your user-code, if --mode=config you can ignore CLI passed options (or allow CLI passed options to override the config options you've manually determined).

This is assuming I understood the problem correctly. While I'm not opposed to a unique option, I think there are better ways to handle the validation you're searching for. (Part of which will only become a thing once v3 is released though).

@CreepySkeleton
Copy link
Contributor

At this moment, clap-rs provides no ergonomic way to specify an option that excludes all other options

I believe this is solved by Arg::exclusive.

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

No branches or pull requests

3 participants