fornwall / rust-script

Run Rust files and expressions as scripts without any setup or compilation step.
https://rust-script.org
Apache License 2.0
1.21k stars 41 forks source link

scripts can't have flags that rust-script itself has #40

Closed jrfondren closed 2 years ago

jrfondren commented 2 years ago

Consider:

# cat help.rs
#! /usr/bin/env rust-script
fn main() {
    if let Some(arg) = std::env::args().skip(1).next() {
        if arg == "--help" {
            println!("???");
        } else {
            println!("{}", arg);
        }
    }
}
# ./help.rs -V
rust-script 0.17.0
# ./help.rs --unique
--unique
# ./help.rs --help
rust-script 0.17.0

Compiles and runs a Rust script.

USAGE:
    rust-script [OPTIONS] [--] [ARGS]
...
joeldierkes commented 2 years ago

A good alternative is to use the Double-Dash parameter in the shell. It "[...] signals the end of options and disables further option processing". [1]

$ ./help.rs -- --help
???

$ ./help.rs -- -V
-V

[1] https://www.baeldung.com/linux/double-dash-in-shell-commands

jrfondren commented 2 years ago

This is a bad alternative for a script that's supposed to have its own CLI interface and its own flags. And people can't even get the message that they need a workaround because the natural "how do I use this" command only tells them about rust-script.

fornwall commented 2 years ago

@jrfondren Thanks a lot for reporting! This should be fixed in the just released version 0.18.0.