Let's rethink defaults, and how they're specified #6148
EvanCarroll
started this conversation in
Ideas
Replies: 1 comment
-
|
FYI #3116 is the issue where we are discussing this |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
When a struct implements
Defaultand is also used as CLI arguments, there's no way to reference theDefaultimplementation's field values in#[arg(default_value_t = ...)]. This forces duplication via intermediate constants.Minimal Example
Current Workaround
Create constants as a proxy:
This is verbose and without it it's error-prone when defaults change.
Requested Feature
Syntactic sugar to reference a struct's Default implementation:
This ensures single source of truth for default values shared between domain logic and CLI.
In my application I have a command.
And I have another command
I want the batching command to share the same defaults as the subcommands above. I don't believe this should require external constants linking the default and the clap definition of the arguments for the subcommand. The defaults are already on a struct.
Beta Was this translation helpful? Give feedback.
All reactions