pub fn classify_command(tokens: &[&str]) -> StringExpand description
Return the canonical command prefix for a slice of command tokens.
The prefix is determined by the COMMAND_ARITY dictionary:
- Tokens that start with
-are treated as flags and skipped — they never contribute to arity. - The arity value
nmeans thatnpositional words (including the base command name) form the canonical prefix. - The longest matching dictionary entry wins (greedy).
- 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");