pub fn split_shell_spec(spec: &str) -> Option<Vec<String>>Expand description
Splits a [general] shell spec into the argv prefix it stands for.
The spec is a program name followed by the flags that make that program read
a command string, for example pwsh -NoProfile -Command. Tokens are
separated by whitespace; a double-quoted run is one token, which is how a
program path containing spaces is written. Backslashes are literal, so a
Windows path needs no doubling here — though TOML itself still requires a
literal string ('...') or doubled backslashes to deliver one.
Returns None when the spec cannot be used as an argv prefix: it is blank,
it leaves a quote unterminated, or its first token — the program to spawn —
is empty. shell_argv reads None as “fall back to
DEFAULT_SHELL_ARGV”, and TrailConfig::validate rejects a non-blank
spec that returns None so the user hears about a typo at startup.
use trail::actions::shell_exec::split_shell_spec;
assert_eq!(
split_shell_spec("pwsh -NoProfile -Command"),
Some(vec!["pwsh".to_owned(), "-NoProfile".to_owned(), "-Command".to_owned()])
);
assert_eq!(
split_shell_spec("\"C:/Program Files/PowerShell/7/pwsh.exe\" -Command"),
Some(vec![
"C:/Program Files/PowerShell/7/pwsh.exe".to_owned(),
"-Command".to_owned(),
])
);
assert_eq!(split_shell_spec(" "), None);
assert_eq!(split_shell_spec("\"unterminated -c"), None);