[Pre-RFC] Flags with Cargo

When using cargo run with something like clap that is proving flags for your code, it seems to be impossible to run the code with flags without having cargo throwing an error, because it cant parse the flag.

Example:
cargo run --extensions test
– > error: Found argument '--extensions' which wasn't expected, or isn't valid in this context

Expected Result:
cargo run -q -b test | --extensions test
– > What ever the code does

Is this just me or would this a be a neat thing to have?
I just but a “|” in between the commands for cargo and the commands for the executable, but that was just a quick “fix”.

Already exists: cargo run -- --extensions test

-- to end the options list is a standard UNIX idiom.

5 Likes

You want

cargo run -- --extensions test

2 Likes

This is a common issue; why don’t we add some help for that cargo error, saying “If you’re trying to pass arguments to the program you’re running, put a -- after the arguments for cargo and before the arguments for the program”?

10 Likes

To add on: A pipe (|) is considered in at least UNIX, and possibly even more places to be an indicator to pass stdout from the execution before it to the stdin of the command after it.