mirror of
https://github.com/SkyfallWasTaken/dinopkg.git
synced 2024-11-22 09:03:41 +00:00
match -> if let
This commit is contained in:
parent
f742244f95
commit
396b6d7124
1 changed files with 22 additions and 26 deletions
|
@ -11,39 +11,35 @@ pub async fn run(script_name: Option<String>) -> Result<()> {
|
||||||
let Some(scripts) = package_json.scripts else {
|
let Some(scripts) = package_json.scripts else {
|
||||||
return Err(eyre!("no `scripts` provided in package.json"));
|
return Err(eyre!("no `scripts` provided in package.json"));
|
||||||
};
|
};
|
||||||
match script_name {
|
if let Some(script_name) = script_name {
|
||||||
Some(script_name) => {
|
match scripts.get(&script_name) {
|
||||||
match scripts.get(&script_name) {
|
Some(script) => {
|
||||||
Some(script) => {
|
println!("{} {}", "$".purple().dimmed(), script.bold().dimmed());
|
||||||
println!("{} {}", "$".purple().dimmed(), script.bold().dimmed());
|
|
||||||
|
|
||||||
let status =
|
let status =
|
||||||
run_script(DEFAULT_SHELL, DEFAULT_SHELL_EXEC_ARG, script, root_path)
|
run_script(DEFAULT_SHELL, DEFAULT_SHELL_EXEC_ARG, script, root_path).await?;
|
||||||
.await?;
|
|
||||||
|
|
||||||
if cfg!(unix) {
|
if cfg!(unix) {
|
||||||
use std::os::unix::process::ExitStatusExt;
|
use std::os::unix::process::ExitStatusExt;
|
||||||
|
|
||||||
if let Some(signal) = status.signal() {
|
if let Some(signal) = status.signal() {
|
||||||
return Err(eyre!(format!("process terminated by signal {signal}")));
|
return Err(eyre!(format!("process terminated by signal {signal}")));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The only time the exit code isn't there is if the process was terminated by a signal.
|
|
||||||
// We check for that above (and on non-Unix systems, there will always be an exit code.)
|
|
||||||
let exit_code = status.code().unwrap();
|
|
||||||
if exit_code != exitcode::OK {
|
|
||||||
return Err(eyre!(format!("process exited with code {exit_code}")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => return Err(eyre!(format!("script `{script_name}` not found"))),
|
|
||||||
|
// The only time the exit code isn't there is if the process was terminated by a signal.
|
||||||
|
// We check for that above (and on non-Unix systems, there will always be an exit code.)
|
||||||
|
let exit_code = status.code().unwrap();
|
||||||
|
if exit_code != exitcode::OK {
|
||||||
|
return Err(eyre!(format!("process exited with code {exit_code}")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
_ => return Err(eyre!(format!("script `{script_name}` not found"))),
|
||||||
}
|
}
|
||||||
_ => {
|
} else {
|
||||||
println!("{}", "Available scripts:".bold().underline());
|
println!("{}", "Available scripts:".bold().underline());
|
||||||
for (key, val) in &scripts {
|
for (key, val) in &scripts {
|
||||||
println!("{} - {}", key.bold(), val.dimmed());
|
println!("{} - {}", key.bold(), val.dimmed());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue