Flatten with prefix #2293
Labels
A-derive
Area: #[derive]` macro API
C-enhancement
Category: Raise on the bar on expectations
S-duplicate
Status: Closed as Duplicate
Milestone
Make sure you completed the following tasks
Describe your use case
Add prefixes to a struct so that we can separate them nice and clean.
Not only that, if we have logically separated the option structure well, we can integrate serde to load config file seamlessly.
For example, we can use a Clap console option
log_console_enabled
for the equivalent oflog.console.enabled
in YAML/JSON variable form or[[log]] [console] enabled
in TOML. This of course is not limited to just these three languages (happy HCL noises). This can be seen as an analogy of what spf13/viper already capable of doing on the Go land.Describe the solution you'd like
Let us do this:
But each of the substructure will have their command line option name prepending with the corresponding prefix, hence promoting a much cleaner code structure, as a side effect, it can also be separated into different crate for better reusing/modularization.
Alternatives, if applicable
This is the current workaround:
Repetitive, painful, and oftentimes prone to miss referentially (e.g. name and struct name not in sync). Also needs to rely on using String Manipulation plugin so much.
Also please look at the additional comment, I have extra reason why I need to specify both name and long together. I have expanded the option file to see what does clap-derive generates in cases like this.
As it turns out, we did found something like this:
and it Is influenced by name option, which by default is the struct item identifier itself, so by exploiting
name
andlong
derive option we can manipulating it to change name while still look like a command line option.I have also gave an updated look of what the workaround is, and put some precursors to what should be generated.
Additional context
Prior issue in structopt: TeXitoi/structopt#114
Issues
However, it does not come without issue. Short option is now getting confusing, as should it get the prefix prepended or not as well. Using verbose "-v" for example, if there is another struct that also use "-v" for version, they will get in conflict and we can't just do both, yet adding prefix to short options is also an unsound solution, so I suggest to delete short option for flattened substructures.
The text was updated successfully, but these errors were encountered: