@@ -5,23 +5,35 @@ import (
55 "fmt"
66 "os"
77 "strings"
8+ "time"
89
910 "github.com/fatih/color"
1011)
1112
13+ // Environment variable values
14+ const (
15+ envTrue = "true"
16+ envFalse = "false"
17+ )
18+
1219var (
1320 // Color functions for different message types
1421 successColor = color .New (color .FgGreen , color .Bold )
1522 errorColor = color .New (color .FgRed , color .Bold )
1623 warningColor = color .New (color .FgYellow , color .Bold )
1724 infoColor = color .New (color .FgCyan )
1825 progressColor = color .New (color .FgBlue )
26+ debugColor = color .New (color .Faint )
1927
2028 // Symbols
2129 successSymbol = "✓"
2230 errorSymbol = "✗"
2331 warningSymbol = "⚠"
2432 infoSymbol = "→"
33+ debugSymbol = "·"
34+
35+ // Verbose mode flag - controls debug output visibility
36+ verboseMode = false
2537)
2638
2739// Success prints a success message in green with a checkmark
@@ -54,6 +66,41 @@ func Progress(format string, args ...interface{}) {
5466 _ , _ = progressColor .Printf (" %s %s\n " , infoSymbol , message )
5567}
5668
69+ // Debug prints a debug message only when verbose mode is enabled
70+ // Messages are dimmed and include a timestamp for debugging
71+ func Debug (format string , args ... interface {}) {
72+ if ! verboseMode {
73+ return
74+ }
75+ message := fmt .Sprintf (format , args ... )
76+ timestamp := time .Now ().Format ("15:04:05.000" )
77+ _ , _ = debugColor .Printf ("%s %s %s\n " , debugSymbol , timestamp , message )
78+ }
79+
80+ // Debugf is an alias for Debug (for consistency with fmt.Printf naming)
81+ func Debugf (format string , args ... interface {}) {
82+ Debug (format , args ... )
83+ }
84+
85+ // SetVerbose enables or disables verbose mode
86+ func SetVerbose (enabled bool ) {
87+ verboseMode = enabled
88+ }
89+
90+ // IsVerbose returns whether verbose mode is enabled
91+ func IsVerbose () bool {
92+ return verboseMode
93+ }
94+
95+ // CheckVerboseEnv checks if DTVEM_VERBOSE environment variable is set
96+ // This is useful for the shim which doesn't have access to CLI flags
97+ func CheckVerboseEnv () {
98+ val := os .Getenv ("DTVEM_VERBOSE" )
99+ if val == "1" || val == envTrue {
100+ verboseMode = true
101+ }
102+ }
103+
57104// Println prints a regular message without color
58105func Println (format string , args ... interface {}) {
59106 fmt .Printf (format + "\n " , args ... )
@@ -99,12 +146,12 @@ func DimText(text string) string {
99146// - unset: prompt interactively
100147func PromptInstall (displayName , version string ) bool {
101148 // Check if running in non-interactive mode (CI/automation)
102- if os .Getenv ("DTVEM_AUTO_INSTALL" ) == "false" {
149+ if os .Getenv ("DTVEM_AUTO_INSTALL" ) == envFalse {
103150 return false
104151 }
105152
106153 // If DTVEM_AUTO_INSTALL=true, auto-install without prompting
107- if os .Getenv ("DTVEM_AUTO_INSTALL" ) == "true" {
154+ if os .Getenv ("DTVEM_AUTO_INSTALL" ) == envTrue {
108155 return true
109156 }
110157
@@ -134,12 +181,12 @@ func PromptInstallMissing[T any](missing []T) bool {
134181 }
135182
136183 // Check if running in non-interactive mode (CI/automation)
137- if os .Getenv ("DTVEM_AUTO_INSTALL" ) == "false" {
184+ if os .Getenv ("DTVEM_AUTO_INSTALL" ) == envFalse {
138185 return false
139186 }
140187
141188 // If DTVEM_AUTO_INSTALL=true, auto-install without prompting
142- if os .Getenv ("DTVEM_AUTO_INSTALL" ) == "true" {
189+ if os .Getenv ("DTVEM_AUTO_INSTALL" ) == envTrue {
143190 return true
144191 }
145192
0 commit comments