Is it possible to define argument dependencies for the Rust CLAP crate in the following way:
- The first argument is a mandatory thing which defines the type of struct to be created
- The arguments following this define the values of the struct fields
For example, we might have two struct
s:
pub struct FirstStruct {
pub field1: String,
pub field2: i64,
}
pub struct SecondStruct {
pub field1: String,
pub field4: String,
pub field5: i32,
}
The command line interface to this would look something like this:
$ ./struct-creator --type FirstStruct --field1 hi --field2 -20
$ ./struct-creator --type SecondStruct --field1 hello --field4 world --field5 100
It is possible to define a subcommand with CLAP. However, this doesn't seem like the correct approach, because a command cannot be in the format --command
, instead it is just command
.
This lead me to conclude that I don't want to format the arguments using a "CLAP command", instead they should all be "CLAP args".
Thus far I have been trying to do this with the derive interface, but using the builder would also be acceptable. I don't know if one offers more flexibility than the other, or if they can do exactly the same things.
The trivial solution would be to make all of the args optional and then just write some runtime logic to explicitly check for valid combinations. But this results in extensive combinatorics logic, which is painful to write, and maintain.