Remove global flags
This commit is contained in:
parent
bb95abdec6
commit
05db35cdfe
17
cmd/main.go
17
cmd/main.go
@ -20,23 +20,17 @@ 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()
|
||||||
var err error
|
var err error
|
||||||
var i int
|
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
i = flag.NFlag() + 1
|
|
||||||
|
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
args = append(args, "help")
|
args = append(args, "help")
|
||||||
@ -57,21 +51,18 @@ 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[1]
|
||||||
|
|
||||||
command := args[i]
|
|
||||||
i++
|
|
||||||
|
|
||||||
c := lifx.NewClient(
|
c := lifx.NewClient(
|
||||||
config.AccessToken,
|
config.AccessToken,
|
||||||
lifx.WithUserAgent(config.userAgent),
|
lifx.WithUserAgent(config.userAgent),
|
||||||
lifx.WithDebug(debugFlag),
|
lifx.WithDebug(config.Debug),
|
||||||
)
|
)
|
||||||
|
|
||||||
ctx := Context{
|
ctx := Context{
|
||||||
Client: c,
|
Client: c,
|
||||||
Config: *config,
|
Config: *config,
|
||||||
Args: args[i:],
|
Args: args[2:],
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd, ok := GetCommand(command)
|
cmd, ok := GetCommand(command)
|
||||||
@ -82,7 +73,7 @@ func Main(args []string) (int, error) {
|
|||||||
|
|
||||||
fs := cmd.Flags
|
fs := cmd.Flags
|
||||||
if fs != nil {
|
if fs != nil {
|
||||||
fs.Parse(args[i:])
|
fs.Parse(args[2:])
|
||||||
ctx.Flags = Flags{FlagSet: fs}
|
ctx.Flags = Flags{FlagSet: fs}
|
||||||
}
|
}
|
||||||
ctx.Name = command
|
ctx.Name = command
|
||||||
|
Loading…
Reference in New Issue
Block a user