github.com/criteo/command-launcher@v0.0.0-20230407142452-fb616f546e98/internal/helper/debug-flag.go (about) 1 package helper 2 3 import ( 4 "os" 5 "strings" 6 ) 7 8 const ( 9 FORCE_SELF_UPDATE = "force_self_update" 10 NO_MERGE_STATUS_CHECK = "no_merge_status_check" 11 SHOW_CMD_EXEC_STDOUT = "show_cmd_exec_stdout" 12 USE_FILE_VAULT = "use_file_vault" 13 ) 14 15 type DebugFlags struct { 16 ForceSelfUpdate bool // Force the self update of the CDT 17 NoMergeStatusCheck bool // do not check merge status when querying merged changes in gerrit 18 ShowCmdExecStdout bool // always show cmd exec stdout to console 19 UseFileVault bool // use file vault instead of system vault 20 } 21 22 // load all debug flags into DebugFlags struct 23 func LoadDebugFlags() DebugFlags { 24 flagsString := os.Getenv("CDT_DEBUG_FLAGS") 25 flags := strings.Split(flagsString, ",") 26 debugFlags := DebugFlags{} 27 for _, flag := range flags { 28 switch flag { 29 case NO_MERGE_STATUS_CHECK: 30 debugFlags.NoMergeStatusCheck = true 31 case SHOW_CMD_EXEC_STDOUT: 32 debugFlags.ShowCmdExecStdout = true 33 case FORCE_SELF_UPDATE: 34 debugFlags.ForceSelfUpdate = true 35 case USE_FILE_VAULT: 36 debugFlags.UseFileVault = true 37 } 38 } 39 return debugFlags 40 } 41 42 // check if a debug flag exists 43 func HasDebugFlag(name string) bool { 44 flagsString := os.Getenv("CDT_DEBUG_FLAGS") 45 if flagsString == "" { 46 return false 47 } 48 flags := strings.Split(flagsString, ",") 49 for _, flag := range flags { 50 if flag == name { 51 return true 52 } 53 } 54 return false 55 }