You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 1, 2022. It is now read-only.
I would like to be able to compute the possible values of an argument dynamically, based on the values provided for some other argument(s).
Use case
I'm working on a CLI which has a goal similar to make.
$ make --help
Usage: make [options] [target] ...
Options:
-f FILE, --file=FILE, --makefile=FILE
Read FILE as a makefile.
The file lists the available targets. Given a value of FILE, I am able to load a list of available target names. I would like to use that list as the possible values for target.
This would affect the validation of target. Ideally, this would also affect its autocompletion.
I would like instead to be able to provide a closure that would compute the possible values for my argument. This closure would take the values of the other app arguments as a parameter.
Workaround
It is already possible to obtain this behavior by parsing the arguments twice (the second time with refined validation):
Comment by fbecart Thursday May 07, 2020 at 06:55 GMT
Thanks @pksunkara for looking into it. I see how clap-rs/clap#1471 is related, as it suggests to have a closure returning the default value of an argument.
This issue remains unique in the following ways:
It is about computing the possible values of an argument.
It requires access to the arguments that have already been provided.
It should influence auto-completion.
It is not related to prompting the user -- which is the primary motive for default value hooks.
Issue by fbecart
Wednesday May 06, 2020 at 12:31 GMT
Originally opened as clap-rs/clap#1910
I would like to be able to compute the possible values of an argument dynamically, based on the values provided for some other argument(s).
Use case
I'm working on a CLI which has a goal similar to
make
.The file lists the available targets. Given a value of
FILE
, I am able to load a list of available target names. I would like to use that list as the possible values fortarget
.This would affect the validation of
target
. Ideally, this would also affect its autocompletion.Currently,
possible_values
is expected to be provided as an array slice (&[&str]
) as theApp
is being built.https://github.com/clap-rs/clap/blob/9d03c8497ce17486e31b19fecbe5bec97ac82d09/src/build/arg/mod.rs#L1712
At that time, the value of
FILE
is not available yet.Wanted solution
I would like instead to be able to provide a closure that would compute the possible values for my argument. This closure would take the values of the other app arguments as a parameter.
Workaround
It is already possible to obtain this behavior by parsing the arguments twice (the second time with refined validation):
However, this workaround doubles the overhead of parsing arguments. Also, this solution does not cover the autocompletion part.
Related issues
The text was updated successfully, but these errors were encountered: