Browse Source

Renamed --debug to --trace, used for light-client and basecoin

pull/1842/head
Ethan Frey 8 years ago
parent
commit
8af1c70a8b
2 changed files with 12 additions and 12 deletions
  1. +3
    -3
      cli/setup.go
  2. +9
    -9
      cli/setup_test.go

+ 3
- 3
cli/setup.go View File

@ -16,7 +16,7 @@ import (
const (
RootFlag = "root"
HomeFlag = "home"
DebugFlag = "debug"
TraceFlag = "trace"
OutputFlag = "output"
EncodingFlag = "encoding"
)
@ -36,7 +36,7 @@ func PrepareBaseCmd(cmd *cobra.Command, envPrefix, defautRoot string) Executor {
// also, default must be empty, so we can detect this unset and fall back
// to --root / TM_ROOT / TMROOT
cmd.PersistentFlags().String(HomeFlag, "", "root directory for config and data")
cmd.PersistentFlags().Bool(DebugFlag, false, "print out full stack trace on errors")
cmd.PersistentFlags().Bool(TraceFlag, false, "print out full stack trace on errors")
cmd.PersistentPreRunE = concatCobraCmdFuncs(bindFlagsLoadViper, cmd.PersistentPreRunE)
return Executor{cmd}
}
@ -92,7 +92,7 @@ func (e Executor) Execute() error {
err := e.Command.Execute()
if err != nil {
// TODO: something cooler with log-levels
if viper.GetBool(DebugFlag) {
if viper.GetBool(TraceFlag) {
fmt.Printf("ERROR: %+v\n", err)
} else {
fmt.Println("ERROR:", err.Error())


+ 9
- 9
cli/setup_test.go View File

@ -184,7 +184,7 @@ func TestSetupUnmarshal(t *testing.T) {
}
}
func TestSetupDebug(t *testing.T) {
func TestSetupTrace(t *testing.T) {
assert, require := assert.New(t), require.New(t)
cases := []struct {
@ -193,22 +193,22 @@ func TestSetupDebug(t *testing.T) {
long bool
expected string
}{
{nil, nil, false, "Debug flag = false"},
{[]string{"--debug"}, nil, true, "Debug flag = true"},
{nil, nil, false, "Trace flag = false"},
{[]string{"--trace"}, nil, true, "Trace flag = true"},
{[]string{"--no-such-flag"}, nil, false, "unknown flag: --no-such-flag"},
{nil, map[string]string{"DBG_DEBUG": "true"}, true, "Debug flag = true"},
{nil, map[string]string{"DBG_TRACE": "true"}, true, "Trace flag = true"},
}
for idx, tc := range cases {
i := strconv.Itoa(idx)
// test command that store value of foobar in local variable
debug := &cobra.Command{
Use: "debug",
trace := &cobra.Command{
Use: "trace",
RunE: func(cmd *cobra.Command, args []string) error {
return errors.Errorf("Debug flag = %t", viper.GetBool(DebugFlag))
return errors.Errorf("Trace flag = %t", viper.GetBool(TraceFlag))
},
}
cmd := PrepareBaseCmd(debug, "DBG", "/qwerty/asdfgh") // some missing dir..
cmd := PrepareBaseCmd(trace, "DBG", "/qwerty/asdfgh") // some missing dir..
viper.Reset()
args := append([]string{cmd.Use}, tc.args...)
@ -219,7 +219,7 @@ func TestSetupDebug(t *testing.T) {
assert.Equal(desired, msg[0], i)
if tc.long && assert.True(len(msg) > 2, i) {
// the next line starts the stack trace...
assert.Contains(msg[1], "TestSetupDebug", i)
assert.Contains(msg[1], "TestSetupTrace", i)
assert.Contains(msg[2], "setup_test.go", i)
}
}


Loading…
Cancel
Save