Skip to content

Commit a9cf9e0

Browse files
fix: :HELP alias lookup, unknown command error, sort by name
1 parent f3b907f commit a9cf9e0

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

pkg/sqlcmd/commands.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,11 +621,19 @@ func helpCommand(s *Sqlcmd, args []string, line uint) error {
621621
// :HELP <command> shows help for a single command
622622
if len(args) > 0 && strings.TrimSpace(args[0]) != "" {
623623
key := strings.ToUpper(strings.TrimSpace(args[0]))
624+
// Look up by map key first, then by command name (handles aliases
625+
// like ED->EDIT, R->READFILE where the key differs from the name)
624626
if cmd, ok := s.Cmd[key]; ok && cmd.help != "" {
625627
_, err := s.GetOutput().Write([]byte(cmd.help))
626628
return err
627629
}
628-
// Unknown command name -- fall through to full listing
630+
for _, cmd := range s.Cmd {
631+
if cmd.name == key && cmd.help != "" {
632+
_, err := s.GetOutput().Write([]byte(cmd.help))
633+
return err
634+
}
635+
}
636+
return fmt.Errorf("'%s' is not a recognized command. Type :HELP for a list of commands", key)
629637
}
630638

631639
// Collect and sort by command name for stable output order
@@ -640,7 +648,7 @@ func helpCommand(s *Sqlcmd, args []string, line uint) error {
640648
}
641649
}
642650
sort.Slice(entries, func(i, j int) bool {
643-
return entries[i].help < entries[j].help
651+
return entries[i].name < entries[j].name
644652
})
645653
var b strings.Builder
646654
for _, e := range entries {

0 commit comments

Comments
 (0)