feat: add natural CLI command aliases - #19
Conversation
📝 WalkthroughWalkthroughThis PR refactors CLI command registration in ChangesCLI Alias Expansion
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/cli/dispatch.go (1)
28-64: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winClean single-source-of-truth refactor. Deriving
commands/aliasesfrom one orderedcommandSpecsslice removes the drift risk between dispatch and help that existed with the old separate tables.One forward-looking gap: there's no guard preventing an alias from colliding with a canonical command name or with the reserved words handled in the
Run()switch (help,version,-h, etc.). The PR description notes an alias/name collision bug was already found and fixed once during review — a small init-time check would catch a repeat of that class of bug automatically as more aliases get added later.♻️ Optional collision guard
func registerCommands() { for _, spec := range commandSpecs { + if _, exists := commands[spec.name]; exists { + panic(fmt.Sprintf("tx9: duplicate command name %q", spec.name)) + } commands[spec.name] = spec.run for _, alias := range spec.aliases { + if _, exists := commands[alias]; exists { + panic(fmt.Sprintf("tx9: alias %q collides with command name", alias)) + } + if _, exists := aliases[alias]; exists { + panic(fmt.Sprintf("tx9: duplicate alias %q", alias)) + } aliases[alias] = spec.name } } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/cli/dispatch.go` around lines 28 - 64, The new command registry in registerCommands() should also validate that aliases do not collide with canonical command names or the reserved Run() switch words like help, version, and -h. Add an init-time guard around commandSpecs processing in internal/cli/dispatch.go that checks each spec.name and alias before populating commands and aliases, and fail fast if any conflict is found so future additions cannot reintroduce alias/name collisions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/cli/dispatch.go`:
- Around line 28-64: The new command registry in registerCommands() should also
validate that aliases do not collide with canonical command names or the
reserved Run() switch words like help, version, and -h. Add an init-time guard
around commandSpecs processing in internal/cli/dispatch.go that checks each
spec.name and alias before populating commands and aliases, and fail fast if any
conflict is found so future additions cannot reintroduce alias/name collisions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1b4c16e0-01c1-4b95-a8ec-b521be9a963e
📒 Files selected for processing (6)
docs/tx9-cli-design.mdinternal/cli/dispatch.gointernal/cli/dispatch_test.gointernal/names/names.gointernal/names/names_test.gosite/public/index.html
Summary
Validation
Review
Note
Add natural language aliases for CLI commands in tx9
new,ls,ssh,shell,export,save,load,restore,update,rm, andremoveto the CLI dispatcher in dispatch.go, backed by a newcommandSpecstruct as a single source of truth for commands and aliases.commandSpecs, and changesprintUsageto acceptio.Writerinstead of*os.File.tx9 updateis an alias fortx9 upgrade.Macroscope summarized c1f5df9.
Greptile Summary
This PR adds natural aliases for existing
tx9CLI commands. The main changes are:new,ls,shell,save,load,restore,update,rm, andremove.Confidence Score: 5/5
Safe to merge with minimal risk.
The dispatcher keeps canonical command behavior intact while deriving aliases and usage output from one source of truth. Name validation blocks the newly introduced aliases. Tests cover alias registration, help output, and reserved names.
No files require special attention.
What T-Rex did
Important Files Changed
Reviews (1): Last reviewed commit: "feat: add natural CLI command aliases" | Re-trigger Greptile