66 "strings"
77
88 "github.com/rsteube/carapace"
9+ "github.com/rsteube/carapace-bin/pkg/actions/tools/fastfetch"
910 "github.com/spf13/cobra"
1011)
1112
@@ -50,8 +51,6 @@ func init() {
5051 return
5152 }
5253
53- actionBools := carapace .ActionValues ("true" , "false" )
54- actionColors := carapace .ActionValues ("black" , "red" , "green" , "yellow" , "blue" , "magenta" , "cyan" , "white" , "default" )
5554 actionMap := carapace.ActionMap {}
5655
5756 for _ , flags := range groups {
@@ -64,11 +63,11 @@ func init() {
6463 switch flag .Arg .Type {
6564 case "bool" :
6665 rootCmd .Flags ().BoolP (flag .Long , flag .Short , false , flag .Desc )
67- actionMap [flag .Long ] = actionBools
66+ actionMap [flag .Long ] = carapace . ActionValues ( "true" , "false" )
6867
6968 case "color" :
7069 rootCmd .Flags ().StringP (flag .Long , flag .Short , "" , flag .Desc )
71- actionMap [flag .Long ] = actionColors
70+ actionMap [flag .Long ] = fastfetch . ActionColors ()
7271
7372 case "command" :
7473 rootCmd .Flags ().StringP (flag .Long , flag .Short , "" , flag .Desc )
@@ -89,10 +88,7 @@ func init() {
8988
9089 case "config" :
9190 rootCmd .Flags ().StringP (flag .Long , flag .Short , "" , flag .Desc )
92- actionMap [flag .Long ] = carapace .ActionExecCommand ("fastfetch" , "--list-presets" , "autocompletion" )(func (output []byte ) carapace.Action {
93- presets := strings .Split (strings .TrimRight (string (output ), "\n " ), "\n " )
94- return carapace .ActionValues (presets ... )
95- })
91+ actionMap [flag .Long ] = fastfetch .ActionPresets ()
9692
9793 case "enum" :
9894 rootCmd .Flags ().StringP (flag .Long , flag .Short , "" , flag .Desc )
@@ -104,13 +100,7 @@ func init() {
104100
105101 case "logo" :
106102 rootCmd .Flags ().StringP (flag .Long , flag .Short , "" , flag .Desc )
107- actionMap [flag .Long ] = carapace .ActionExecCommand ("fastfetch" , "--list-logos" , "autocompletion" )(func (output []byte ) carapace.Action {
108- res := []string {"none" , "Disable logo" , "small" , "Show small logo if supported" }
109- for _ , logo := range strings .Split (strings .TrimRight (string (output ), "\n " ), "\n " ) {
110- res = append (res , logo , "Builtin logo" )
111- }
112- return carapace .ActionValuesDescribed (res ... )
113- })
103+ actionMap [flag .Long ] = fastfetch .ActionLogos ()
114104
115105 case "num" :
116106 rootCmd .Flags ().IntP (flag .Long , flag .Short , 0 , flag .Desc )
@@ -121,14 +111,7 @@ func init() {
121111
122112 case "structure" :
123113 rootCmd .Flags ().StringP (flag .Long , flag .Short , "" , flag .Desc )
124- actionMap [flag .Long ] = carapace .ActionExecCommand ("fastfetch" , "--list-modules" , "autocompletion" )(func (output []byte ) carapace.Action {
125- var texts []string
126- for _ , line := range strings .Split (strings .TrimRight (string (output ), "\n " ), "\n " ) {
127- name , desc , _ := strings .Cut (line , ":" )
128- texts = append (texts , name , desc )
129- }
130- return carapace .ActionValuesDescribed (texts ... ).UniqueList (":" )
131- })
114+ actionMap [flag .Long ] = fastfetch .ActionModules ().UniqueList (":" )
132115
133116 default :
134117 rootCmd .Flags ().StringP (flag .Long , flag .Short , "" , flag .Desc )
0 commit comments