Skip to content

Commit

Permalink
Added nocolor to jr template list
Browse files Browse the repository at this point in the history
  • Loading branch information
ugol committed Feb 13, 2024
1 parent ead7ce9 commit 81b0f10
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkg/cmd/templateList.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ var templateListCmd = &cobra.Command{
return
}

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

var Red = "\033[31m"
var Green = "\033[32m"
var Reset = "\033[0m"
Expand All @@ -59,10 +61,12 @@ var templateListCmd = &cobra.Command{

t, _ := os.ReadFile(path)
valid, err := isValidTemplate(t)
if valid {
fmt.Print(Green)
} else {
fmt.Print(Red)
if !(noColor) {
if valid {
fmt.Print(Green)
} else {
fmt.Print(Red)
}
}

if fullPath {
Expand All @@ -79,8 +83,9 @@ var templateListCmd = &cobra.Command{
}
return nil
})
fmt.Println(Reset)

if !(noColor) {
fmt.Println(Reset)
}
if err != nil {
fmt.Printf("Error in %q: %v\n", templateDir, err)
return
Expand All @@ -107,4 +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")
}

0 comments on commit 81b0f10

Please sign in to comment.