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

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

Closed
jrfondren opened this issue Nov 7, 2021 · 3 comments
Closed

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

jrfondren opened this issue Nov 7, 2021 · 3 comments

Comments

@jrfondren
Copy link

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
Copy link

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
Copy link
Author

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
Copy link
Owner

fornwall commented Nov 9, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants