Add debug output support

This commit is contained in:
Ryan Cavicchioni 2021-03-29 17:22:22 -05:00
parent a4638db773
commit 9338631de9
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
4 changed files with 17 additions and 0 deletions

View File

@ -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 (

View File

@ -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
}

View File

@ -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{

View File

@ -60,3 +60,9 @@ func YesNo(v bool) string {
}
return "no"
}
func Debugf(format string, a ...interface{}) {
if GetConfig().Debug {
fmt.Printf(format, a...)
}
}