Skip to content

Commit

Permalink
tidy root command
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Sep 17, 2023
1 parent ff88156 commit b5a1041
Show file tree
Hide file tree
Showing 5 changed files with 512 additions and 323 deletions.
38 changes: 38 additions & 0 deletions cmd/carapace/cmd/action/completer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package action

import (
"encoding/json"

"github.com/rsteube/carapace"
"github.com/rsteube/carapace/pkg/style"
)

func ActionCompleters() carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.ActionExecCommand("carapace", "--list=json")(func(output []byte) carapace.Action {
var completers []struct {
Name string
Description string
Spec string
Overlay string
}
if err := json.Unmarshal(output, &completers); err != nil {
return carapace.ActionMessage(err.Error())
}

vals := make([]string, 0, len(completers))
for _, completer := range completers {
s := style.Default
if completer.Spec != "" {
s = style.Blue
}
if completer.Overlay != "" {
s = style.Of(s, style.Underlined)
}

vals = append(vals, completer.Name, completer.Description, s)
}
return carapace.ActionStyledValuesDescribed(vals...)
})
})
}
Loading

0 comments on commit b5a1041

Please sign in to comment.