Add debug output support
This commit is contained in:
parent
a4638db773
commit
9338631de9
@ -17,6 +17,7 @@ type Config struct {
|
||||
OutputFormat string `toml:"output_format"`
|
||||
Colors map[string][]float32 `toml:"colors"`
|
||||
userAgent string
|
||||
Debug bool `toml:"debug"`
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -35,6 +35,9 @@ func LsCmd(ctx Context) (int, error) {
|
||||
}
|
||||
|
||||
lights, err := c.ListLights(selector)
|
||||
|
||||
Debugf("%+v\n", lights)
|
||||
|
||||
if err != nil {
|
||||
return ExitFailure, err
|
||||
}
|
||||
|
@ -20,11 +20,15 @@ func init() {
|
||||
RegisterCommand(NewCmdToggle())
|
||||
RegisterCommand(NewCmdVersion())
|
||||
RegisterCommand(NewCmdBreathe())
|
||||
|
||||
flag.BoolVar(&debugFlag, "debug", false, "debug mode")
|
||||
flag.BoolVar(&debugFlag, "d", false, "debug mode")
|
||||
}
|
||||
|
||||
var Version string
|
||||
var BuildDate string
|
||||
var GitCommit string
|
||||
var debugFlag bool
|
||||
|
||||
func Main(args []string) (int, error) {
|
||||
var config *Config = GetConfig()
|
||||
@ -53,12 +57,15 @@ func Main(args []string) (int, error) {
|
||||
return ExitFailure, fmt.Errorf("fatal: %s", err)
|
||||
}
|
||||
|
||||
config.Debug = debugFlag
|
||||
|
||||
command := args[i]
|
||||
i++
|
||||
|
||||
c := lifx.NewClient(
|
||||
config.AccessToken,
|
||||
lifx.WithUserAgent(config.userAgent),
|
||||
lifx.WithDebug(debugFlag),
|
||||
)
|
||||
|
||||
Context := Context{
|
||||
|
@ -60,3 +60,9 @@ func YesNo(v bool) string {
|
||||
}
|
||||
return "no"
|
||||
}
|
||||
|
||||
func Debugf(format string, a ...interface{}) {
|
||||
if GetConfig().Debug {
|
||||
fmt.Printf(format, a...)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user