Compare commits
2 Commits
3c0254c9a1
...
9338631de9
Author | SHA1 | Date | |
---|---|---|---|
9338631de9
|
|||
a4638db773
|
@ -17,14 +17,28 @@ type Config struct {
|
||||
OutputFormat string `toml:"output_format"`
|
||||
Colors map[string][]float32 `toml:"colors"`
|
||||
userAgent string
|
||||
Debug bool `toml:"debug"`
|
||||
}
|
||||
|
||||
var (
|
||||
DefaultConfig = Config{
|
||||
userAgent: initUserAgent(),
|
||||
}
|
||||
globalConfig *Config = NewConfig()
|
||||
)
|
||||
|
||||
func NewConfig() *Config {
|
||||
c := new(Config)
|
||||
c.userAgent = initUserAgent()
|
||||
c.Debug = false
|
||||
c.OutputFormat = "simple"
|
||||
return c
|
||||
}
|
||||
|
||||
func GetConfig() *Config {
|
||||
return globalConfig
|
||||
}
|
||||
|
||||
// Validate configuration struct
|
||||
func (c *Config) Validate() error {
|
||||
var err error
|
||||
@ -69,7 +83,7 @@ func (c *Config) MergeWithEnv() {
|
||||
|
||||
func LoadConfig(s string) (*Config, error) {
|
||||
var err error
|
||||
var c *Config = &Config{}
|
||||
var c *Config = GetConfig()
|
||||
|
||||
*c = DefaultConfig
|
||||
|
||||
@ -83,7 +97,7 @@ func LoadConfig(s string) (*Config, error) {
|
||||
func LoadConfigFile(configPath string) (*Config, error) {
|
||||
var err error
|
||||
|
||||
var c *Config = &Config{}
|
||||
var c *Config = GetConfig()
|
||||
|
||||
*c = DefaultConfig
|
||||
|
||||
|
@ -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,14 +20,18 @@ 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
|
||||
var config *Config = GetConfig()
|
||||
var err error
|
||||
var i int
|
||||
|
||||
@ -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...)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user