Skip to content

Commit

Permalink
Merge pull request #99 from DopplerHQ/tom_debug
Browse files Browse the repository at this point in the history
Print active configuration when specifying --print-config flag
  • Loading branch information
Piccirello authored Jun 2, 2020
2 parents f278c8b + 3e718a0 commit 0fa02f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
26 changes: 15 additions & 11 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ var rootCmd = &cobra.Command{
if silent {
utils.LogWarning("--silent has no effect when used with --debug")
}
}

utils.LogDebug("Active configuration")
// this output does not honor --silent
printConfig := utils.GetBoolFlagIfChanged(cmd, "print-config", false)
if printConfig {
fmt.Println("Active configuration")
printer.ScopedConfigSource(configuration.LocalConfig(cmd), false, true)
fmt.Println("")
}
Expand Down Expand Up @@ -106,14 +110,13 @@ func loadFlags(cmd *cobra.Command) {
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
// catch any panics
// catch any panics in non-dev builds
defer func() {
if version.IsDevelopment() {
return
}
if err := recover(); err != nil {
fmt.Fprintf(os.Stderr, fmt.Sprintf("%s %v\n", color.Red.Render("Doppler Exception:"), err))
os.Exit(1)
if !version.IsDevelopment() {
if err := recover(); err != nil {
fmt.Fprintf(os.Stderr, fmt.Sprintf("%s %v\n", color.Red.Render("Doppler Exception:"), err))
os.Exit(1)
}
}
}()

Expand All @@ -138,7 +141,8 @@ func init() {
rootCmd.PersistentFlags().Bool("no-read-env", false, "do not read enclave config from the environment")
rootCmd.PersistentFlags().String("scope", ".", "the directory to scope your config to")
rootCmd.PersistentFlags().String("configuration", configuration.UserConfigFile, "config file")
rootCmd.PersistentFlags().Bool("json", false, "output json")
rootCmd.PersistentFlags().Bool("debug", false, "output additional information when encountering errors")
rootCmd.PersistentFlags().Bool("silent", false, "disable output of info messages")
rootCmd.PersistentFlags().Bool("json", utils.OutputJSON, "output json")
rootCmd.PersistentFlags().Bool("debug", utils.Debug, "output additional information")
rootCmd.PersistentFlags().Bool("print-config", false, "output active configuration")
rootCmd.PersistentFlags().Bool("silent", utils.Silent, "disable output of info messages")
}
6 changes: 0 additions & 6 deletions pkg/utils/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"encoding/json"
"fmt"
"os"
"runtime/debug"

"gopkg.in/gookit/color.v1"
)
Expand Down Expand Up @@ -97,11 +96,6 @@ func ErrExit(e error, exitCode int, messages ...string) {
}
}

if Debug {
fmt.Fprintln(os.Stderr, color.Red.Render("\nStacktrace:"))
debug.PrintStack()
}

os.Exit(exitCode)
}

Expand Down

0 comments on commit 0fa02f2

Please sign in to comment.