github.com/drycc/workflow-cli@v1.5.3-0.20240322092846-d4ee25983af9/cmd/shortcuts.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "sort" 6 7 "github.com/drycc/workflow-cli/cli" 8 ) 9 10 // ShortcutsList displays all relevant shortcuts for the CLI. 11 func (d *DryccCmd) ShortcutsList() error { 12 d.Println(sortShortcuts()) 13 14 return nil 15 } 16 17 func sortShortcuts() string { 18 var ( 19 strBuilder string 20 keys []string 21 ) 22 23 // NOTE(bacongobbler): go does not guarantee an iteration order when iterating over a map, 24 // so to work around this we can sort the keys and iterate using the key array 25 for k := range cli.Shortcuts { 26 keys = append(keys, k) 27 } 28 sort.Strings(keys) 29 30 for _, k := range keys { 31 strBuilder += fmt.Sprintf("%s -> %s\n", k, cli.Shortcuts[k]) 32 } 33 34 return strBuilder 35 }