feat(command): implement command aliasing
Implement command aliasing in CmdRegistry and update command parsing to resolve aliases. - Added `aliases` field to `CmdRegistry` . - Added `alias()` method to register short names. - Added `resolve()` method to map aliases to canonical names. - Updated `parse()` and `interactive()` to use `resolve()` . - Added unit tests for alias resolution in `src/command/parse.rs` . Co-Authored-By: fiddlerwoaroof/git-smart-commit (unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q5_K_XL)
This commit is contained in:
@ -181,4 +181,56 @@ mod tests {
|
||||
assert!(parse_line("add-category").is_err());
|
||||
assert!(parse_line("set-cell 100").is_err());
|
||||
}
|
||||
|
||||
// ── Alias resolution ────────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn alias_add_cat_resolves_to_add_category() {
|
||||
let cmds = parse_line("add-cat Region").unwrap();
|
||||
assert_eq!(cmds.len(), 1);
|
||||
assert_eq!(cmds[0].name(), "add-category");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_formula_resolves_to_add_formula() {
|
||||
let cmds = parse_line(r#"formula Product "Total = A + B""#).unwrap();
|
||||
assert_eq!(cmds.len(), 1);
|
||||
assert_eq!(cmds[0].name(), "add-formula");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_add_view_resolves_to_create_view() {
|
||||
let cmds = parse_line("add-view MyView").unwrap();
|
||||
assert_eq!(cmds.len(), 1);
|
||||
assert_eq!(cmds[0].name(), "create-view");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_q_bang_resolves_to_force_quit() {
|
||||
let cmds = parse_line("q!").unwrap();
|
||||
assert_eq!(cmds.len(), 1);
|
||||
assert_eq!(cmds[0].name(), "force-quit");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_does_not_interfere_with_canonical_q() {
|
||||
let cmds = parse_line("q").unwrap();
|
||||
assert_eq!(cmds.len(), 1);
|
||||
assert_eq!(cmds[0].name(), "q");
|
||||
}
|
||||
|
||||
// ── add-items command ───────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn parse_add_items_multiple() {
|
||||
let cmds = parse_line("add-items Region North South East").unwrap();
|
||||
assert_eq!(cmds.len(), 1);
|
||||
assert_eq!(cmds[0].name(), "add-items");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_items_requires_at_least_two_args() {
|
||||
assert!(parse_line("add-items").is_err());
|
||||
assert!(parse_line("add-items Region").is_err());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user