-
I code this: #[derive(Parser)]
pub struct Args {
/// Specify the input file name
#[clap(short)]
pub input: String,
/// Specify the output file name
#[clap(short, default_value = input + ".xx")]
pub output: String,
} The compiler told me that the Is there any way to use field in macro attribute declaration? If I can't do this, how should I achieve the functionality? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
No, this won't work. What the macro expands out to is a CLI definition followed by a parse phase. One reason we can't make syntax like this work is that In #3008, we are looking at exploring custom runtime default logic that also allows a user to provide custom help hints which would enable something like this. |
Beta Was this translation helpful? Give feedback.
No, this won't work. What the macro expands out to is a CLI definition followed by a parse phase. One reason we can't make syntax like this work is that
default_value
is used for help text and we might not be able to instantiateArgs
to accessinput
when help is shown. Even if we instead make this about referencing the intermediate value as we build upArgs
, there are still cases whereinput
won't exist (e.g.$ cmd --help
).In #3008, we are looking at exploring custom runtime default logic that also allows a user to provide custom help hints which would enable something like this.