parse_line

Function parse_line 

Source
pub fn parse_line(input: &str) -> (String, Vec<String>)
Expand description

Parse a single command line into (command, args) with shell-like rules:

  • Whitespace separates tokens
  • Double quotes (“…”) and single quotes (‘…’) preserve whitespace within
  • Supports escaping of quotes and spaces with backslash (e.g., " or \ )
  • Mixed quoting is supported; escapes are processed within quoted segments
  • Empty or whitespace-only input returns (“”, vec![])

§Examples

Basic splitting:

use modcli::parser::parse_line;
let (cmd, args) = parse_line("hello world there");
assert_eq!(cmd, "hello");
assert_eq!(args, vec!["world", "there"]);

Quoted segments preserved:

use modcli::parser::parse_line;
let (cmd, args) = parse_line("say \"hello world\" 'and universe'");
assert_eq!(cmd, "say");
assert_eq!(args, vec!["hello world", "and universe"]);

Escaped spaces and quotes:

use modcli::parser::parse_line;
let (cmd, args) = parse_line("run path\\ with\\ spaces \"quote\"");
assert_eq!(cmd, "run");
assert_eq!(args, vec!["path with spaces", "quote"]);