package line
import (
"slices"
"strings"
"github.com/spf13/cobra"
)
var (
Reset = "\x1b[0m"
Bold = "\x1b[1m"
Dim = "\x1b[2m"
Underscore = "\x1b[4m"
Blink = "\x1b[5m"
Reverse = "\x1b[7m"
BoldReset = "\x1b[22m"
DimReset = "\x1b[22m"
UnderscoreReset = "\x1b[24m"
BlinkReset = "\x1b[25m"
ReverseReset = "\x1b[27m"
GreenFG = "\x1b[32m"
YellowFG = "\x1b[33m"
ResetFG = "\x1b[39m"
BrightWhiteFG = "\x1b[38;05;244m"
)
func HighlightCommand (done , args []string , root *cobra .Command , cmdColor string ) ([]string , []string ) {
highlighted := make ([]string , 0 )
var rest []string
if len (args ) == 0 {
return done , args
}
for _ , cmd := range root .Commands () {
cmdFound := strings .Split (cmd .Use , " " )[0 ] == strings .TrimSpace (args [0 ])
if slices .Contains (cmd .Aliases , strings .TrimSpace (args [0 ])) {
cmdFound = true
break
}
if cmdFound {
highlighted = append (highlighted , Bold +cmdColor +args [0 ]+ResetFG +BoldReset )
rest = args [1 :]
return append (done , highlighted ...), rest
}
}
return append (done , highlighted ...), args
}
func HighlightCommandFlags (done , args []string , flagColor string ) ([]string , []string ) {
highlighted := make ([]string , 0 )
var rest []string
if len (args ) == 0 {
return done , args
}
for _ , arg := range args {
if strings .HasPrefix (arg , "-" ) || strings .HasPrefix (arg , "--" ) {
highlighted = append (highlighted , Bold +flagColor +arg +ResetFG +BoldReset )
} else {
highlighted = append (highlighted , arg )
}
}
return append (done , highlighted ...), rest
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .