Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/internal/flags/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var LogModeFlag = &Metadata{
Name: "log-mode",
Shorthand: "m",
Usage: "Log mode (text, logfmt, json, hidden)",
Default: "logfmt",
Default: "",
Required: false,
}

Expand Down
2 changes: 1 addition & 1 deletion docs/cli/flow_exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ flow exec EXECUTABLE_ID [args...] [flags]

```
-h, --help help for exec
-m, --log-mode string Log mode (text, logfmt, json, hidden) (default "logfmt")
-m, --log-mode string Log mode (text, logfmt, json, hidden)
-p, --param stringArray Set a parameter value by env key. (i.e. KEY=value) Use multiple times to set multiple parameters.This will override any existing parameter values defined for the executable.
```

Expand Down
33 changes: 24 additions & 9 deletions internal/services/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@ import (
)

func init() {
if _, exists := os.LookupEnv("TERM"); !exists {
_ = os.Setenv("TERM", "xterm-256color")
}
if _, exists := os.LookupEnv("FORCE_COLOR"); !exists {
_ = os.Setenv("FORCE_COLOR", "1")
}
if _, exists := os.LookupEnv("CLICOLOR_FORCE"); !exists {
_ = os.Setenv("CLICOLOR_FORCE", "1")
}
setupColorEnvironment()
}

// RunCmd executes a command in the current shell in a specific directory.
Expand Down Expand Up @@ -144,3 +136,26 @@ func stdOutWriter(mode io.LogMode, logger io.Logger, logFields ...any) stdio.Wri
func stdErrWriter(mode io.LogMode, logger io.Logger, logFields ...any) stdio.Writer {
return io.StdErrWriter{LogFields: logFields, Logger: logger, LogMode: &mode}
}

func setupColorEnvironment() {
hasColorPreference := os.Getenv("NO_COLOR") != "" ||
os.Getenv("FORCE_COLOR") != "" ||
os.Getenv("CLICOLOR_FORCE") != ""

if !hasColorPreference {
isCI := os.Getenv("CI") != "" || os.Getenv("GITHUB_ACTIONS") != ""
isTesting := strings.HasSuffix(os.Args[0], ".test")

if isCI || isTesting {
_ = os.Setenv("NO_COLOR", "1")
} else {
_ = os.Setenv("FORCE_COLOR", "1")
_ = os.Setenv("CLICOLOR_FORCE", "1")
}
}

// Always ensure TERM is set if colors might be used
if os.Getenv("NO_COLOR") == "" && os.Getenv("TERM") == "" {
_ = os.Setenv("TERM", "xterm-256color")
}
}
9 changes: 0 additions & 9 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,3 @@ func IsZeroValue(v interface{}) bool {
}
return reflect.DeepEqual(v, reflect.Zero(reflect.TypeOf(v)).Interface())
}

//nolint:lll
const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"

var re = regexp.MustCompile(ansi)

func StripAnsi(str string) string {
return re.ReplaceAllString(str, "")
}
3 changes: 1 addition & 2 deletions tests/secret_cmds_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

internalUtils "github.com/jahvon/flow/internal/utils"
"github.com/jahvon/flow/tests/utils"
)

Expand Down Expand Up @@ -45,7 +44,7 @@ var _ = Describe("vault/secrets e2e", Ordered, func() {
Expect(lines).ToNot(BeEmpty())
parts := strings.Split(strings.TrimSpace(lines[0]), ":")
Expect(parts).To(HaveLen(2))
encryptionKey := strings.TrimSpace(internalUtils.StripAnsi(parts[1]))
encryptionKey := strings.TrimSpace(parts[1])
Expect(os.Setenv(keyEnv, encryptionKey)).To(Succeed())
})

Expand Down
1 change: 1 addition & 0 deletions tests/utils/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ func setTestEnv(t ginkgo.FullGinkgoTInterface, configDir, cacheDir string) {
t.Setenv(filesystem.FlowConfigDirEnvVar, configDir)
t.Setenv(filesystem.FlowCacheDirEnvVar, cacheDir)
t.Setenv(store.BucketEnv, "")
t.Setenv("NO_COLOR", "1")
}

func expectInternalMockLoggerCalls(logger *tuikitIOMocks.MockLogger) {
Expand Down
Loading