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