From 05db35cdfedb404e611eba96ff44c4ec404c130e Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Tue, 30 Mar 2021 21:04:57 -0500 Subject: [PATCH] Remove global flags --- cmd/main.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 4365d96..5de8643 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -20,23 +20,17 @@ 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() var err error - var i int flag.Parse() - i = flag.NFlag() + 1 if len(args) == 1 { args = append(args, "help") @@ -57,21 +51,18 @@ func Main(args []string) (int, error) { return ExitFailure, fmt.Errorf("fatal: %s", err) } - config.Debug = debugFlag - - command := args[i] - i++ + command := args[1] c := lifx.NewClient( config.AccessToken, lifx.WithUserAgent(config.userAgent), - lifx.WithDebug(debugFlag), + lifx.WithDebug(config.Debug), ) ctx := Context{ Client: c, Config: *config, - Args: args[i:], + Args: args[2:], } cmd, ok := GetCommand(command) @@ -82,7 +73,7 @@ func Main(args []string) (int, error) { fs := cmd.Flags if fs != nil { - fs.Parse(args[i:]) + fs.Parse(args[2:]) ctx.Flags = Flags{FlagSet: fs} } ctx.Name = command