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

Support something similar to serde(default), clap(default_value_t). #12

Open
cbeck88 opened this issue Oct 14, 2024 · 0 comments
Open

Comments

@cbeck88
Copy link
Owner

cbeck88 commented Oct 14, 2024

clap-derive has a parameter called default_value_t, used like arg(default_value_t = expr), or arg(default_value_t). (discussion)

serde has slightly different take, the syntax is serde(default) or serde(default = "path-to-function"). (docu: https://serde.rs/attr-default.html)


We currently have default_value = "..." which is basically the same clap.

I haven't found arg(default_value_t = ...) to be that useful. serde(default) is very useful -- I actually didn't know that arg(default_value_t) worked like that in clap.

The naming default_value_t kind of irks me -- it clashes with traditional systems programming conventions.

Traditionally, in C and C++, _t indicates that something is a type.

For example, size_t is a type used to represent a size.

Many more examples from C standard library and POSIX: https://stackoverflow.com/a/231807/3598119

In JSON for modern C++, the _t things in the API are types.

In clap however, default_value_t = ... is assigned a value, and is not a type.

I find this confusing, and so I'd rather break with clap's naming and follow serde, but follow clap's semantics. So we would have arg(default) means that it is initialized with Default::default(), and arg(default = expr) mean that it is initialized with the expression.

(We would not, like serde, require that you create a named function somewhere else, when there is no good reason to make you do that afaict. We are already wrapping whatever expr you supply in a hidden function in the implementation of many things like value_parser and validation_predicate.)

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

1 participant