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

Idiomatic way to include optional arguments in command #51

Closed rob-p closed 2 years ago

rob-p commented 2 years ago

I'd like to run a command / function where what is run is composed of some dynamic options passed in by the user. So I have a command and depending on whether or not the user passes some argument to my rust program, I'd like to run (via run_fun!) another external program either including or not this option. There are several such options, so enumerating all possibilities grows combinatorially.

I tried building a single command string, but realized the run_fun! macro won't tokenize that on spaces the way the subprocess needs. What is the recommended way to achieve this functionality in cmd_lib?

Thanks! Rob

rust-shell-script commented 2 years ago

You can use $[] to access vector variable, see README or closed issues for some examples.