Skip to content

Commit

Permalink
Log informational messages to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
Piccirello committed Nov 16, 2021
1 parent 5f10039 commit 8129aa2
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 73 deletions.
8 changes: 4 additions & 4 deletions pkg/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ var completionInstallCmd = &cobra.Command{
utils.HandleError(err, "Unable to write completion file")
}

utils.Log("Your shell has been configured for Doppler CLI completions! Restart your shell to apply.")
utils.Log("")
utils.Print("Your shell has been configured for Doppler CLI completions! Restart your shell to apply.")
utils.Print("")
if utils.IsMacOS() {
utils.Log("Note: The homebrew 'bash-completion' package is required for completions to work. See https://docs.brew.sh/Shell-Completion for more info.")
utils.Print("Note: The homebrew 'bash-completion' package is required for completions to work. See https://docs.brew.sh/Shell-Completion for more info.")
} else {
utils.Log("Note: The 'bash-completion' package is required for completions to work. See https://github.com/scop/bash-completion for more info.")
utils.Print("Note: The 'bash-completion' package is required for completions to work. See https://github.com/scop/bash-completion for more info.")
}
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func updateConfigs(cmd *cobra.Command, args []string) {
}

if !yes {
utils.LogWarning("Renaming this config may break your current deploys.")
utils.PrintWarning("Renaming this config may break your current deploys.")
if !utils.ConfirmationPrompt("Continue?", false) {
utils.Log("Aborting")
return
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ and your config file. Flags have the highest priority; config file has the least
Run: func(cmd *cobra.Command, args []string) {
jsonFlag := utils.OutputJSON

utils.Log(fmt.Sprintf("%s %s", color.Green.Render("Configuration file:"), configuration.UserConfigFile))
utils.Print(fmt.Sprintf("%s %s", color.Green.Render("Configuration file:"), configuration.UserConfigFile))

config := configuration.LocalConfig(cmd)
printer.ScopedConfigSource(config, jsonFlag, true, false)
Expand Down Expand Up @@ -253,15 +253,15 @@ var configureResetCmd = &cobra.Command{
yes := utils.GetBoolFlag(cmd, "yes")

if !yes {
utils.LogWarning("This will delete all local CLI configuration and auth tokens")
utils.PrintWarning("This will delete all local CLI configuration and auth tokens")
if !utils.ConfirmationPrompt("Continue?", false) {
utils.Log("Aborting")
return
}
}

configuration.ClearConfig()
utils.Log("Configuration has been reset. Please run 'doppler login' to authenticate")
utils.Print("Configuration has been reset. Please run 'doppler login' to authenticate")
},
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func renameEnvironment(cmd *cobra.Command, args []string) {

if !yes {
if newSlug != "" {
utils.LogWarning("Modifying your environment's slug may break your current deploys. All configs within this environment will also be renamed.")
utils.PrintWarning("Modifying your environment's slug may break your current deploys. All configs within this environment will also be renamed.")
}
yes = utils.ConfirmationPrompt(prompt, false)
}
Expand Down
30 changes: 15 additions & 15 deletions pkg/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ var loginCmd = &cobra.Command{
if err1 == nil && err2 == nil && prevScope == newScope {
if cmd.Flags().Changed("scope") {
// user specified scope flag, show yes/no override prompt
utils.LogWarning("This scope is already authorized from a previous login.")
utils.Log("")
utils.PrintWarning("This scope is already authorized from a previous login.")
utils.Print("")
if !utils.ConfirmationPrompt("Overwrite existing login", false) {
utils.Log("Exiting")
utils.Print("Exiting")
return
}
} else {
// scope flag wasn't specified, show option to scope to current directory
utils.LogWarning("You have already logged in.")
utils.Log("")
utils.Log("Would you like to scope your new login to the current directory, or overwrite the existing global login?")
utils.PrintWarning("You have already logged in.")
utils.Print("")
utils.Print("Would you like to scope your new login to the current directory, or overwrite the existing global login?")

cwd := utils.Cwd()
options := []string{fmt.Sprintf("Scope login to current directory (%s)", cwd), fmt.Sprintf("Overwrite global login (%s)", newScope)}
Expand Down Expand Up @@ -94,7 +94,7 @@ var loginCmd = &cobra.Command{

if copyAuthCode {
if err := utils.CopyToClipboard(code); err != nil {
utils.LogWarning("Unable to copy to clipboard")
utils.PrintWarning("Unable to copy to clipboard")
}
}

Expand All @@ -113,10 +113,10 @@ var loginCmd = &cobra.Command{
}

if printURL {
utils.Log(fmt.Sprintf("Complete authorization at %s", authURL))
utils.Print(fmt.Sprintf("Complete authorization at %s", authURL))
}
utils.Log(fmt.Sprintf("Your auth code is:\n%s\n", color.Green.Render(code)))
utils.Log("Waiting...")
utils.Print(fmt.Sprintf("Your auth code is:\n%s\n", color.Green.Render(code)))
utils.Print("Waiting...")

// auth flow must complete within 5 minutes
timeout := 5 * time.Minute
Expand Down Expand Up @@ -148,8 +148,8 @@ var loginCmd = &cobra.Command{
}

if err, ok := response["error"]; ok {
utils.Log("")
utils.Log(fmt.Sprint(err))
utils.Print("")
utils.Print(fmt.Sprint(err))

os.Exit(1)
}
Expand Down Expand Up @@ -183,8 +183,8 @@ var loginCmd = &cobra.Command{

configuration.Set(configuration.Scope, options)

utils.Log("")
utils.Log(fmt.Sprintf("Welcome, %s", name))
utils.Print("")
utils.Print(fmt.Sprintf("Welcome, %s", name))

if prevConfig.Token.Value != "" {
prevScope, err1 := filepath.Abs(prevConfig.Token.Scope)
Expand Down Expand Up @@ -240,7 +240,7 @@ Your saved configuration will be updated.`,
}
}

utils.Log("Auth token has been rolled")
utils.Print("Auth token has been rolled")
},
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ func revokeToken(cmd *cobra.Command, args []string) {
invalidTokenError := err.Code >= 400 && err.Code < 500
if invalidTokenError {
utils.LogDebug("Failed to revoke token")
utils.Log(err.Unwrap().Error())
utils.Print(err.Unwrap().Error())
} else {
utils.HandleError(err.Unwrap(), err.Message)
}
} else {
utils.Log("Auth token has been revoked")
utils.Print("Auth token has been revoked")
}

if updateConfig {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func updateProjects(cmd *cobra.Command, args []string) {
}

if !yes {
utils.LogWarning("Renaming this project may break your current deploys.")
utils.PrintWarning("Renaming this project may break your current deploys.")
if !utils.ConfirmationPrompt("Continue?", false) {
utils.Log("Aborting")
return
Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ var rootCmd = &cobra.Command{

// this output does not honor --silent
if printConfig {
fmt.Println("Active configuration")
utils.LogDebug("Active configuration")
printer.ScopedConfigSource(configuration.LocalConfig(cmd), false, true, true)
fmt.Println("")
utils.LogDebug("")
}

plain := utils.GetBoolFlagIfChanged(cmd, "plain", false)
Expand Down Expand Up @@ -107,12 +107,12 @@ func checkVersion(command string) {
} else if utils.IsWindows() {
utils.Log(fmt.Sprintf("Update: Doppler CLI %s is available\n\nYou can update via 'scoop update doppler'\n", versionCheck.LatestVersion))
} else {
utils.Log(color.Green.Sprintf("An update is available."))
utils.Print(color.Green.Sprintf("An update is available."))

changes, apiError := controllers.CLIChangeLog()
if apiError.IsNil() {
printer.ChangeLog(changes, 1, false)
utils.Log("")
utils.Print("")
}

prompt := fmt.Sprintf("Install Doppler CLI %s", versionCheck.LatestVersion)
Expand Down Expand Up @@ -177,7 +177,7 @@ func Execute() {
defer func() {
if !version.IsDevelopment() {
if err := recover(); err != nil {
fmt.Fprintf(os.Stderr, fmt.Sprintf("%s %v\n", color.Red.Render("Doppler Exception:"), err))
utils.Log(fmt.Sprintf("%s %v\n", color.Red.Render("Doppler Exception:"), err))
os.Exit(1)
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ var runCleanCmd = &cobra.Command{
if _, err := os.Stat(defaultFallbackDir); err != nil {
if os.IsNotExist(err) {
utils.LogDebug("Fallback directory does not exist")
utils.Log("Nothing to clean")
utils.Print("Nothing to clean")
return
}

Expand Down Expand Up @@ -233,9 +233,9 @@ var runCleanCmd = &cobra.Command{
}

if deleted == 1 {
utils.Log(fmt.Sprintf("%s %d fallback file\n", action, deleted))
utils.Print(fmt.Sprintf("%s %d fallback file\n", action, deleted))
} else {
utils.Log(fmt.Sprintf("%s %d fallback files\n", action, deleted))
utils.Print(fmt.Sprintf("%s %d fallback files\n", action, deleted))
}
},
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/cmd/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ func setSecrets(cmd *cobra.Command, args []string) {
utils.HandleError(errors.New("Secret value must be provided when using --no-interactive"))
}

utils.Log("Enter your secret value")
utils.Log("When finished, type a newline followed by a period")
utils.Log("Run 'doppler secrets set --help' for more information")
utils.Log("———————————————————— START INPUT ————————————————————")
utils.Print("Enter your secret value")
utils.Print("When finished, type a newline followed by a period")
utils.Print("Run 'doppler secrets set --help' for more information")
utils.Print("———————————————————— START INPUT ————————————————————")
}

isNewline := false
Expand All @@ -274,7 +274,7 @@ func setSecrets(cmd *cobra.Command, args []string) {
isNewline = false

if isPreviousNewline && s == "." {
utils.Log("————————————————————— END INPUT —————————————————————")
utils.Print("————————————————————— END INPUT —————————————————————")
break
}

Expand Down Expand Up @@ -459,7 +459,7 @@ func downloadSecrets(cmd *cobra.Command, args []string) {
}

if !saveFile {
fmt.Println(string(body))
utils.Print(string(body))
return
}

Expand Down Expand Up @@ -490,7 +490,7 @@ func downloadSecrets(cmd *cobra.Command, args []string) {
utils.HandleError(err, "Unable to write the secrets file")
}

utils.Log(fmt.Sprintf("Downloaded secrets to %s", filePath))
utils.Print(fmt.Sprintf("Downloaded secrets to %s", filePath))
}

func substituteSecrets(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -566,7 +566,7 @@ func substituteSecrets(cmd *cobra.Command, args []string) {
if err != nil {
utils.HandleError(err, "Unable to save rendered data to file")
}
utils.Log(fmt.Sprintf("Rendered data saved to %s", outputFilePath))
utils.Print(fmt.Sprintf("Rendered data saved to %s", outputFilePath))
} else {
_, err = os.Stdout.WriteString(buffer.String())
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions pkg/cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func setup(cmd *cobra.Command, args []string) {
case models.FlagSource.String():
saveToken = true
case models.EnvironmentSource.String():
utils.Log(valueFromEnvironmentNotice("DOPPLER_TOKEN"))
utils.Print(valueFromEnvironmentNotice("DOPPLER_TOKEN"))
saveToken = true
}
}
Expand Down Expand Up @@ -82,11 +82,11 @@ func setup(cmd *cobra.Command, args []string) {
case models.FlagSource.String():
selectedProject = localConfig.EnclaveProject.Value
case models.EnvironmentSource.String():
utils.Log(valueFromEnvironmentNotice("DOPPLER_PROJECT"))
utils.Print(valueFromEnvironmentNotice("DOPPLER_PROJECT"))
selectedProject = localConfig.EnclaveProject.Value
default:
if useRepoConfig && repoConfig.Setup.Project != "" {
utils.Log("Auto-selecting project from repo config file")
utils.Print("Auto-selecting project from repo config file")
selectedProject = repoConfig.Setup.Project
break
}
Expand Down Expand Up @@ -117,11 +117,11 @@ func setup(cmd *cobra.Command, args []string) {
case models.FlagSource.String():
selectedConfig = localConfig.EnclaveConfig.Value
case models.EnvironmentSource.String():
utils.Log(valueFromEnvironmentNotice("DOPPLER_CONFIG"))
utils.Print(valueFromEnvironmentNotice("DOPPLER_CONFIG"))
selectedConfig = localConfig.EnclaveConfig.Value
default:
if useRepoConfig && repoConfig.Setup.Config != "" {
utils.Log("Auto-selecting config from repo config file")
utils.Print("Auto-selecting config from repo config file")
selectedConfig = repoConfig.Setup.Config
break
}
Expand All @@ -131,7 +131,7 @@ func setup(cmd *cobra.Command, args []string) {
utils.HandleError(apiError.Unwrap(), apiError.Message)
}
if len(configs) == 0 {
utils.Log("You project does not have any configs")
utils.Print("You project does not have any configs")
break
}

Expand Down Expand Up @@ -184,7 +184,7 @@ func selectProject(projects []models.ProjectInfo, prevConfiguredProject string,
if len(projects) == 1 {
// the user is expecting to a prompt, so print a message instead
if canPromptUser {
utils.Log(fmt.Sprintf("%s %s", color.Bold.Render("Selected only available project:"), options[0]))
utils.Print(fmt.Sprintf("%s %s", color.Bold.Render("Selected only available project:"), options[0]))
}
return projects[0].ID
}
Expand Down Expand Up @@ -220,7 +220,7 @@ func selectConfig(configs []models.ConfigInfo, selectedConfiguredProject bool, p
config := configs[0].Name
// the user is expecting to a prompt, so print a message instead
if canPromptUser {
utils.Log(fmt.Sprintf("%s %s", color.Bold.Render("Selected only available config:"), config))
utils.Print(fmt.Sprintf("%s %s", color.Bold.Render("Selected only available config:"), config))
}
return config
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var updateCmd = &cobra.Command{
if force {
utils.Log(fmt.Sprintf("Already running the latest version but proceeding anyway due to --force flag"))
} else {
utils.Log(fmt.Sprintf("You are already running the latest version"))
utils.Print(fmt.Sprintf("You are already running the latest version"))
return
}
}
Expand All @@ -54,24 +54,24 @@ var updateCmd = &cobra.Command{
}

func installCLIUpdate() {
utils.Log("Updating...")
utils.Print("Updating...")
wasUpdated, installedVersion, controllerErr := controllers.RunInstallScript()
if !controllerErr.IsNil() {
utils.HandleError(controllerErr.Unwrap(), controllerErr.Message)
}

if wasUpdated {
utils.Log(fmt.Sprintf("Installed CLI %s", installedVersion))
utils.Print(fmt.Sprintf("Installed CLI %s", installedVersion))

if changes, apiError := controllers.CLIChangeLog(); apiError.IsNil() {
utils.Log("\nWhat's new:")
utils.Print("\nWhat's new:")
printer.ChangeLog(changes, 1, false)
utils.Log("\nTip: run 'doppler changelog' to see all latest changes")
utils.Print("\nTip: run 'doppler changelog' to see all latest changes")
}

utils.Log("")
utils.Print("")
} else {
utils.Log(fmt.Sprintf("You are already running the latest version"))
utils.Print(fmt.Sprintf("You are already running the latest version"))
}

}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func RunInstallScript() (bool, string, Error) {
// log output before checking error
utils.LogDebug(fmt.Sprintf("Executing \"%s\"", strings.Join(command, " ")))
if utils.Debug {
fmt.Println(strOut)
// use Fprintln rather than LogDebug so that we don't display a duplicate "DEBUG" prefix
fmt.Fprintln(os.Stderr, strOut)
}
if err != nil {
exitCode := 1
Expand Down
2 changes: 1 addition & 1 deletion pkg/printer/enclave.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func ConfigLog(log models.ConfigLog, jsonFlag bool, diff bool) {

for i, logDiff := range log.Diff {
if i != 0 {
fmt.Print("\n")
fmt.Println("")
}

if logDiff.Name == "" {
Expand Down

0 comments on commit 8129aa2

Please sign in to comment.