From 9338631de93949132994da267d30d98fe3b3b840 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Mon, 29 Mar 2021 17:22:22 -0500 Subject: [PATCH] Add debug output support --- cmd/config.go | 1 + cmd/ls.go | 3 +++ cmd/main.go | 7 +++++++ cmd/util.go | 6 ++++++ 4 files changed, 17 insertions(+) diff --git a/cmd/config.go b/cmd/config.go index d37b824..32a1a7d 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -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 ( diff --git a/cmd/ls.go b/cmd/ls.go index 713d308..3734d03 100644 --- a/cmd/ls.go +++ b/cmd/ls.go @@ -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 } diff --git a/cmd/main.go b/cmd/main.go index cfce3be..b9485e3 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -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{ diff --git a/cmd/util.go b/cmd/util.go index f4bce3b..a398280 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -60,3 +60,9 @@ func YesNo(v bool) string { } return "no" } + +func Debugf(format string, a ...interface{}) { + if GetConfig().Debug { + fmt.Printf(format, a...) + } +} \ No newline at end of file