Skip to content

Commit

Permalink
added --nocolor to several list/show commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ugol committed Feb 13, 2024
1 parent 65f9c69 commit 5fb79df
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 17 deletions.
14 changes: 11 additions & 3 deletions pkg/cmd/emitterList.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ var emitterListCmd = &cobra.Command{
Long: `List all available emitters`,
Run: func(cmd *cobra.Command, args []string) {

noColor, _ := cmd.Flags().GetBool("nocolor")

var Green = ""
var Reset = ""
if !noColor {
Green = "\033[32m"
Reset = "\033[0m"
}

fmt.Println()
fmt.Println("List of JR emitters:")
fmt.Println()

var Green = "\033[32m"
var Reset = "\033[0m"

for _, v := range emitters {
fmt.Printf("%s%s%s\n", Green, v.Name, Reset)
}
Expand All @@ -48,4 +54,6 @@ var emitterListCmd = &cobra.Command{

func init() {
emitterCmd.AddCommand(emitterListCmd)
emitterListCmd.Flags().BoolP("nocolor", "n", false, "Do not color output")

}
12 changes: 10 additions & 2 deletions pkg/cmd/emitterShow.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ jr emitter show net_device`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {

var Green = "\033[32m"
var Reset = "\033[0m"
noColor, _ := cmd.Flags().GetBool("nocolor")

var Green = ""
var Reset = ""
if !noColor {
Green = "\033[32m"
Reset = "\033[0m"
}

fmt.Println()
for _, v := range emitters {
Expand All @@ -61,4 +67,6 @@ jr emitter show net_device`,

func init() {
emitterCmd.AddCommand(emitterShowCmd)
emitterShowCmd.Flags().BoolP("nocolor", "n", false, "Do not color output")

}
27 changes: 19 additions & 8 deletions pkg/cmd/functionList.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,24 @@ func doList(cmd *cobra.Command, args []string) {
find, _ := cmd.Flags().GetBool("find")
run, _ := cmd.Flags().GetBool("run")
isMarkdown, _ := cmd.Flags().GetBool("markdown")
noColor, _ := cmd.Flags().GetBool("nocolor")

if category {
for k, v := range functions.DescriptionMap() {
if strings.Contains(v.Category, args[0]) {
printFunction(k, isMarkdown)
printFunction(k, isMarkdown, noColor)
}
}
} else if find {
for k, v := range functions.DescriptionMap() {
if strings.Contains(v.Description, args[0]) || strings.Contains(v.Name, args[0]) {
printFunction(k, isMarkdown)
printFunction(k, isMarkdown, noColor)
}
}
} else if len(args) == 1 {

if run {
f, found := printFunction(args[0], isMarkdown)
f, found := printFunction(args[0], isMarkdown, noColor)
if found {
fmt.Println()
cmd := exec.Command("/bin/sh", "-c", f.Example)
Expand All @@ -92,26 +93,31 @@ func doList(cmd *cobra.Command, args []string) {
cmd.Run()
}
} else {
printFunction(args[0], isMarkdown)
printFunction(args[0], isMarkdown, noColor)
}
} else {
count := 0
for k := range functions.FunctionsMap() {
count++
printFunction(k, isMarkdown)
printFunction(k, isMarkdown, noColor)
}
fmt.Println()
fmt.Printf("Total functions: %d\n", count)
}
fmt.Println()
}

func printFunction(name string, isMarkdown bool) (functions.FunctionDescription, bool) {
func printFunction(name string, isMarkdown bool, noColor bool) (functions.FunctionDescription, bool) {
f, found := functions.Description(name)

var Cyan = ""
var Reset = ""
if !noColor {
Cyan = "\033[36m"
Reset = "\033[0m"
}

if !isMarkdown {
var Reset = "\033[0m"
var Cyan = "\033[36m"

if found {
fmt.Println()
Expand Down Expand Up @@ -151,9 +157,14 @@ func init() {
functionCmd.AddCommand(functionListCmd)
functionListCmd.Flags().BoolP("category", "c", false, "IndexOf in category")
functionListCmd.Flags().BoolP("find", "f", false, "IndexOf in description and name")
functionListCmd.Flags().BoolP("markdown", "m", false, "Output the list as markdown")
functionListCmd.Flags().BoolP("run", "r", false, "Run the example")
functionListCmd.Flags().BoolP("nocolor", "n", false, "Do not color output")

functionManCmd.Flags().BoolP("category", "c", false, "IndexOf in category")
functionManCmd.Flags().BoolP("markdown", "m", false, "Output the list as markdown")
functionManCmd.Flags().BoolP("find", "f", false, "IndexOf in description and name")
functionManCmd.Flags().BoolP("run", "r", false, "Run the example")
functionManCmd.Flags().BoolP("nocolor", "n", false, "Do not color output")

}
11 changes: 9 additions & 2 deletions pkg/cmd/producerList.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ var producerListCmd = &cobra.Command{
"jr producer list",
Run: func(cmd *cobra.Command, args []string) {

var Green = "\033[32m"
var Reset = "\033[0m"
noColor, _ := cmd.Flags().GetBool("nocolor")

var Green = ""
var Reset = ""
if !noColor {
Green = "\033[32m"
Reset = "\033[0m"
}

fmt.Println()
fmt.Println("List of JR producers:")
Expand All @@ -53,4 +59,5 @@ var producerListCmd = &cobra.Command{

func init() {
producerCmd.AddCommand(producerListCmd)
producerListCmd.Flags().BoolP("nocolor", "n", false, "Do not color output")
}
2 changes: 1 addition & 1 deletion pkg/cmd/templateList.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,5 @@ func isValidTemplate(t []byte) (bool, error) {
func init() {
templateCmd.AddCommand(templateListCmd)
templateListCmd.Flags().BoolP("fullPath", "f", false, "Print full path")
templateListCmd.Flags().BoolP("nocolor", "n", false, "Do not color the output")
templateListCmd.Flags().BoolP("nocolor", "n", false, "Do not color output")
}
2 changes: 1 addition & 1 deletion pkg/cmd/templateShow.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ var templateShowCmd = &cobra.Command{

func init() {
templateCmd.AddCommand(templateShowCmd)
templateShowCmd.Flags().BoolP("nocolor", "n", false, "disable colorized output")
templateShowCmd.Flags().BoolP("nocolor", "n", false, "Do not color output")
}

0 comments on commit 5fb79df

Please sign in to comment.