Initialize `RunCommand` struct from input provided via stdin or via CLI arguments. # Arguments `arguments` - Optional arguments to pass to the command `executable` - The command to execute `exit_code` - The expected exit code upon success, if non-zero `stdin` - Optional JSON or YAML input provided via stdin # Errors Error message then exit if the `RunCommand` struct cannot be initialized from
(arguments: Option<Vec<String>>, executable: Option<String>, exit_code: i32, stdin: Option<String>)
| 28 | /// |
| 29 | /// Error message then exit if the `RunCommand` struct cannot be initialized from the provided inputs. |
| 30 | pub fn parse_input(arguments: Option<Vec<String>>, executable: Option<String>, exit_code: i32, stdin: Option<String>) -> runcommand::RunCommand { |
| 31 | let command: runcommand::RunCommand; |
| 32 | if let Some(input) = stdin { |
| 33 | debug!("Input: {}", input); |
| 34 | command = match serde_json::from_str(&input) { |
| 35 | Ok(json) => json, |
| 36 | Err(err) => { |
| 37 | error!("{}: {err}", t!("utils.invalidInput")); |
| 38 | exit(EXIT_INVALID_INPUT); |
| 39 | } |
| 40 | } |
| 41 | } else if let Some(executable) = executable { |
| 42 | command = runcommand::RunCommand { |
| 43 | executable, |
| 44 | arguments, |
| 45 | exit_code, |
| 46 | }; |
| 47 | } |
| 48 | else { |
| 49 | error!("{}", t!("utils.executableRequired")); |
| 50 | exit(EXIT_INVALID_INPUT); |
| 51 | } |
| 52 | command |
| 53 | } |
| 54 | |
| 55 | /// Setup tracing subscriber based on the provided trace level and format. |
| 56 | /// |