reitermarkus / cargo-eval

Cargo Subcommand
Apache License 2.0
102 stars 6 forks source link

disable clap suggestions, as they're applying to script arguments #3

Closed jrfondren closed 4 years ago

jrfondren commented 4 years ago

Consider a script named 'nohelp.rs':

#! /home/jrfondren/.cargo/bin/cargo-eval --

fn main() {
    println!("{}", std::env::args().nth(1)
             .unwrap_or("no arg".to_string()));
}

This script is intended to just print its first argument, but unfortunately it silently has many invalid arguments due to clap's suggestions feature:

$ ./nohelp.rs 'this is ok'
this is ok
$ ./nohelp.rs help
error: The subcommand 'help' wasn't recognized
        Did you mean 'help'?

If you believe you received this message in error, try re-running with 'cargo eval -- help'

USAGE:
    cargo eval [FLAGS OPTIONS] [--] <script> <args>...

For more information try --help
$ ./nohelp.rs help-people.helpful.com
error: The subcommand 'help-people.helpful.com' wasn't recognized
        Did you mean 'help'?

If you believe you received this message in error, try re-running with 'cargo eval -- help-people.helpful.com'

USAGE:
    cargo eval [FLAGS OPTIONS] [--] <script> <args>...

For more information try --help
$ ./nohelp.rs hello
error: The subcommand 'hello' wasn't recognized
        Did you mean 'help'?

If you believe you received this message in error, try re-running with 'cargo eval -- hello'

USAGE:
    cargo eval [FLAGS OPTIONS] [--] <script> <args>...

For more information try --help

This PR disables that. Note that, even with 'suggestions' disabled, something like the unfortunate #! there is required, as 'help' and other arguments can still get snatched out of the arguments intended for a script:

#! /usr/bin/env cargo-eval

fn main() {
    println!("{}", std::env::args().nth(1)
             .unwrap_or("no arg".to_string()));
}

and as used:

$ ./nohelp.rs help
cargo-eval 0.1.0
Compiles and runs “Cargoified Rust scripts”.

USAGE:
    cargo eval [FLAGS OPTIONS] [--] <script> <args>
...
$ ./nohelp.rs --please no
error: Found argument '--please' which wasn't expected, or isn't valid in this context

USAGE:
    cargo eval [FLAGS OPTIONS] [--] <script> <args>...

For more information try --help
jrfondren commented 4 years ago

build failures are due to deprecations unrelated to this PR.

jrfondren commented 4 years ago

No issues tracker. Is this fork dead?

just renamed a bunch of internal sites to not reuse filenames (such as index.rs) due to this:

$ rm -rf ~/.cache/cargo-eval/
$ cat eval1/hi.rs
#! /usr/bin/env cargo-eval
fn main() { println!("hello eval1/hi.rs") }
$ cat eval2/hi.rs
#! /usr/bin/env cargo-eval
fn main() { println!("hello eval2/hi.rs") }
$ ./eval1/hi.rs
hello eval1/hi.rs
$ ./eval2/hi.rs
hello eval2/hi.rs
$ ./eval1/hi.rs
hello eval2/hi.rs
$ 

and encountered the same problem at the commandline:

$ cargo eval -e 'let x: i16 = -32767; x.abs()'
32767
$ cargo eval -e 'let x: i16 = -32768; x.abs()'
32767
reitermarkus commented 4 years ago

@jrfondren, sorry, I completely missed this apparently.

Merged in https://github.com/reitermarkus/cargo-eval/commit/5f07a45e13d789a613d70f6353455a7fd7c15ad7.