You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use clap::Parser;#[derive(Parser)]structCli{#[arg(short, env)]foo:Vec<i32>,}fnmain(){let cli = Cli::parse();println!("{:?}", cli.foo);}
Steps to reproduce the bug with the above code
cargo run -- -f 1 -f 2
Output: [1, 2]
FOO=1 cargo run
Output: [1]
FOO="1 2" cargo run
Output: error: invalid value '1 2' for '-f <FOO>': invalid digit found in string
FOO="1,2" cargo run
Output: error: invalid value '1,2' for '-f <FOO>': invalid digit found in string
FOO="1, 2" cargo run
Output: error: invalid value '1, 2' for '-f <FOO>': invalid digit found in string
FOO="[1, 2]" cargo run
Output: error: invalid value '[1, 2]' for '-f <FOO>': invalid digit found in string
Actual Behaviour
When using env on a vector field, multiple values can be passed by specifying the argument multiple times on the CLI, however the same can't be done when using env vars (because the OS doesn't support specifying the same env var twice).
Expected Behaviour
I think it makes sense to have consistency between CLI args and env vars when using the env option even when the field is a vector. If that's not possible, the user should probably know about the expected behavior or limitation.
Potential solutions I can think of:
Parse env var values when using env on vector fields and split the string into vector elements. Something like FOO="[1, 2]" can likely be used.
Document the fact that when using env on vector fields, only one value can be specified.
Disallow env on vector fields.
Additional Context
No response
Debug Output
No response
The text was updated successfully, but these errors were encountered:
Thanks @epage. I wonder if there is a way to reconcile the behavior of CLI args and env vars for vector values, as well as whether it would make sense to do so. The problem of course isn't in clap itself, it's the fact that at the OS level it's meaningless to specify the same env var twice.
Please complete the following tasks
Rust Version
rustc 1.70.0 (90c541806 2023-05-31)
Clap Version
4.3.11
Minimal reproducible code
Steps to reproduce the bug with the above code
Output:
[1, 2]
Output:
[1]
Output:
error: invalid value '1 2' for '-f <FOO>': invalid digit found in string
Output:
error: invalid value '1,2' for '-f <FOO>': invalid digit found in string
Output:
error: invalid value '1, 2' for '-f <FOO>': invalid digit found in string
Output:
error: invalid value '[1, 2]' for '-f <FOO>': invalid digit found in string
Actual Behaviour
When using
env
on a vector field, multiple values can be passed by specifying the argument multiple times on the CLI, however the same can't be done when using env vars (because the OS doesn't support specifying the same env var twice).Expected Behaviour
I think it makes sense to have consistency between CLI args and env vars when using the
env
option even when the field is a vector. If that's not possible, the user should probably know about the expected behavior or limitation.Potential solutions I can think of:
env
on vector fields and split the string into vector elements. Something likeFOO="[1, 2]"
can likely be used.env
on vector fields, only one value can be specified.env
on vector fields.Additional Context
No response
Debug Output
No response
The text was updated successfully, but these errors were encountered: