Skip to content

Commit

Permalink
feat: add script description in list command
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudingcity committed Sep 9, 2020
1 parent 29186ce commit 32b7cf6
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions internal/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ type Shell struct {
historyPath string
current string
scripts map[string]*cobra.Command
names []string
infos []info
quit bool
}

type info struct {
name string
description string
}

func New(in io.ReadCloser, out io.Writer) *Shell {
return &Shell{
in: in,
Expand All @@ -56,7 +61,11 @@ func New(in io.ReadCloser, out io.Writer) *Shell {
func (s *Shell) Register(scripts ...*cobra.Command) {
for _, script := range scripts {
s.scripts[script.Name()] = script
s.names = append(s.names, script.Name())
info := info{
name: script.Name(),
description: script.Short,
}
s.infos = append(s.infos, info)
}
}

Expand Down Expand Up @@ -134,8 +143,8 @@ func (s *Shell) helpCmd() {

func (s *Shell) listCmd() {
s.println("Scripts:")
for _, name := range s.names {
s.printf(" %s\n", yellow(name))
for _, info := range s.infos {
s.printf(" %-26s %s\n", yellow(info.name), info.description)
}
}

Expand Down Expand Up @@ -200,8 +209,8 @@ func (s *Shell) autoCompleter() readline.AutoCompleter {
for _, cmd := range cmds {
if cmd.cmd == "\\s" || cmd.cmd == "\\r" {
var subs []readline.PrefixCompleterInterface
for _, name := range s.names {
subs = append(subs, readline.PcItem(name))
for _, info := range s.infos {
subs = append(subs, readline.PcItem(info.name))
}
pcs = append(pcs, readline.PcItem(cmd.cmd, subs...))
} else {
Expand Down

0 comments on commit 32b7cf6

Please sign in to comment.