Skip to content

Commit f9748d5

Browse files
fix: ensure zarf say honors no-color (#4850)
Signed-off-by: Micah Nagel <micah.nagel@defenseunicorns.com> Co-authored-by: Austin Abro <37223396+AustinAbro321@users.noreply.github.com>
1 parent 48574c2 commit f9748d5

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/cmd/say.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ package cmd
77
import (
88
"fmt"
99
"os"
10+
"regexp"
1011

1112
"github.com/spf13/cobra"
13+
14+
"github.com/zarf-dev/zarf/src/pkg/message"
1215
)
1316

1417
func sayCommand() *cobra.Command {
@@ -17,7 +20,13 @@ func sayCommand() *cobra.Command {
1720
Short: "Print Zarf logo",
1821
Long: "Print out the adorable Zarf logo",
1922
RunE: func(_ *cobra.Command, _ []string) error {
20-
_, err := fmt.Fprintln(os.Stderr, logo())
23+
out := logo()
24+
if !message.ColorEnabled() {
25+
// Strip ANSI color codes - https://regex101.com/r/YFyIwC/2
26+
ansiRegex := regexp.MustCompile(`\x1b\[(.*?)m`)
27+
out = ansiRegex.ReplaceAllString(out, "")
28+
}
29+
_, err := fmt.Fprintln(os.Stderr, out)
2130
return err
2231
},
2332
}

0 commit comments

Comments
 (0)