-
Notifications
You must be signed in to change notification settings - Fork 13
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
Any interest in an additional convenience wrapper? #10
Comments
interesting. thinking about how to do it. |
That could work, but it loses some of the convenience of a dedicated function. I guess the API would be something like let mut options = ScriptOptions::new();
options.validate_exit_code(true);
let output = run_script!(
r#"
echo "Test"
"#,
&options
).unwrap(); which is significantly more verbose. It also has the disadvantage of giving the One comparison that might be helpful is to the standard library. It has many different Following the standard library's example, what if let output = run_script_or_exit!(
r#"
echo "Test"
"#
); |
good idea. |
My view is that failing to expose standard err isn't too bad: it's typically blank when the program exits successfully; even if it's not blank, it's usually extra info that's useful when the program is called interactively (and not that useful inside a script); and – in the rare case when neither of the above apply and the user wants to receive standard err – users still have access to the more verbose
Will do! |
cool. i still prefer the err as well as sometimes processes decide to write to err (strange) |
@codesections I just pushed a new function and macro for this. |
I have been using
run_script
fairly heavily in various CLI contexts, and frequently encounter the situation where I would like to run a script that I expect to succeed. If it does, I want to do something with the output; if it doesn't I want to print the relevant error to the end user and exit my script. To accomplish this, I was writing a lot of code like the following:(Not with
ls
; it's just a simple command to have as an example.)After writing this more times than I should have, it occurred to me to write a very simple helper function to reduce the verbosity of this code. So I now write
I believe that the use case of exiting on errors might be a common one when using
run_script
for basic scripting. (One reason I believe that this may be the case is that many people like to useset -e
in Bash scripts to achieve a similar result of exiting on any non-zero exit code). If that is the case, would it be worth including the helper function inrun_script
?Features Description
A helper function that returns standard output or (if the command fails) exits and displays the standard error output.
Describe the solution you'd like
This is the simple helper function I am currently using. Would it make sense to add it to
run_script
?Code Sample
The text was updated successfully, but these errors were encountered: