Skip to main content

classify_command

Function classify_command 

Source
pub fn classify_command(tokens: &[&str]) -> String
Expand description

Return the canonical command prefix for a slice of command tokens.

The prefix is determined by the COMMAND_ARITY dictionary:

  1. Tokens that start with - are treated as flags and skipped — they never contribute to arity.
  2. The arity value n means that n positional words (including the base command name) form the canonical prefix.
  3. The longest matching dictionary entry wins (greedy).
  4. If no dictionary entry matches, the single base command word is returned as the prefix.

§Examples

assert_eq!(classify_command(&["git", "status", "-s"]),            "git status");
assert_eq!(classify_command(&["git", "push", "origin"]),          "git push");
assert_eq!(classify_command(&["cargo", "check", "--workspace"]),  "cargo check");
assert_eq!(classify_command(&["npm", "run", "dev"]),              "npm run dev");
assert_eq!(classify_command(&["ls", "-la"]),                      "ls");