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

Add try_from_env() function #122

Open
Timmmm opened this issue Feb 14, 2022 · 1 comment
Open

Add try_from_env() function #122

Timmmm opened this issue Feb 14, 2022 · 1 comment

Comments

@Timmmm
Copy link

Timmmm commented Feb 14, 2022

It would be nice if the library contained this function:

/// Fallible version of argh::from_env().
pub fn try_from_env<T: argh::TopLevelCommand>() -> std::result::Result<T, argh::EarlyExit> {
    let strings: Vec<String> = std::env::args().collect();
    let cmd = cmd(&strings[0], &strings[0]);
    let strs: Vec<&str> = strings.iter().map(|s| s.as_str()).collect();
    T::from_args(&[cmd], &strs[1..])
}

Use case is a bit niche - it's a command that is run with no stdout or stderr so the only way I can see CLI errors is to write them to a file, and I can't do that with argh::from_env().

Also seems a bit weird that argh::EarlyExit uses Result<(), ()> and String rather than just being Result<(), String>.

@shijunti19
Copy link

Support does not want to see error output

image

    let args: Args = argh::from_env();
    println!("args {:?}", args);

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

2 participants