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

Cargo not passing arguments to binary #1855

Closed
jhod0 opened this issue Jul 28, 2015 · 5 comments
Closed

Cargo not passing arguments to binary #1855

jhod0 opened this issue Jul 28, 2015 · 5 comments
Labels
A-documenting-cargo-itself Area: Cargo's documentation

Comments

@jhod0
Copy link

jhod0 commented Jul 28, 2015

The cargo run command passes arguments like 1 2 3 or <filename> to the binary, but sees flags as arguments to cargo itself.

I have a crate which produces an executable which takes flags in the form of ./<mybinary> -r 4. Executing cargo run --bin <targetname> 4 works fine, but cargo run --bin <targetname> -r 4 gives the error:

Unknown flag: '-r'

Usage
    cargo run [options] [--] [<args>...]

So, it looks like Cargo is trying to parse arguments intended for my binary. I think all arguments after --bin <targetname> should be passed straight to the executable. Arguments to cargo would then have to be before --bin.

My version info:

$ cargo --version
cargo 0.4.0-nightly (84ef25d 2015-07-23) (built 2015-07-23)
@alexcrichton
Copy link
Member

This is part of our option parsing, you need to pass -- as a separator between the flags to your binary and the flags to Cargo. cargo run --bin foo -- -r 4 should do the trick!

@jhod0
Copy link
Author

jhod0 commented Jul 29, 2015

Ahh great that works fine. Thanks!
That might be worth an explanation in cargo help run :)

@alexcrichton
Copy link
Member

Sounds like a reasonable idea! reopening as a docs bug to add info about -- to the cargo help page.

@alexcrichton alexcrichton reopened this Jul 29, 2015
@alexcrichton alexcrichton added the A-documenting-cargo-itself Area: Cargo's documentation label Jul 29, 2015
@ProtectedMode
Copy link

Shouldn't the usage just be changed from:
cargo run [options] [--] [<args>...]
to
cargo run [options] [-- <args>...]?

@alexcrichton
Copy link
Member

Unfortunately that would require -- be passed 100% of the time, which we don't want to do. It's just required for flags, not necessarily for positional arguments (e.g. cargo run foo)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documenting-cargo-itself Area: Cargo's documentation
Projects
None yet
Development

No branches or pull requests

3 participants