rust-shell-script / rust_cmd_lib

Common rust command-line macros and utilities, to write shell-script like tasks in a clean, natural and rusty way
https://docs.rs/cmd_lib/
Apache License 2.0
1.05k stars 37 forks source link

Can cmd_lib cooperate with Command? #69

Open jesHrz opened 2 months ago

jesHrz commented 2 months ago

I am not very familiar with Rust.

Though cmd_lib can pass a vector to run_cmd!, the vector item must still be the same type, which is inconvenient.

For example, trying to pass arguments wich contains both literal &str and integer u64 needs to be like:

let a = 999999u32;
let b = 88888u64;
let args = vec!("-a".to_string(), a.to_string(), "-b".to_string(), b.to_string());
run_cmd!(some_cmd $[args]);

all items must be converted to String. Using Command can be more easy:

let mut cmd = Command::new(some_cmd);
cmd.arg("-a").arg(a.to_string());
cmd.arg("-b").arg(b.to_string());
let output = cmd.output();

this example can easily construct the command and corresponding arguments, but it is hard to control the subprocess, while cmd_lib is easy to run the command but hard to construct it.

I'm wondering, how can I use Command to construct commands and use cmd_lib to launch the command? If the answer is no, when cmd_lib can cooperate with Command, would it be better for both command construction and controlling?