Add support for parsing global flags
This commit is contained in:
parent
1ef900c44c
commit
b1a5844b6b
13
cmd/main.go
13
cmd/main.go
@ -29,6 +29,10 @@ var GitCommit string
|
|||||||
func Main(args []string) (int, error) {
|
func Main(args []string) (int, error) {
|
||||||
var config *Config
|
var config *Config
|
||||||
var err error
|
var err error
|
||||||
|
var i int
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
i = flag.NFlag() + 1
|
||||||
|
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
args = append(args, "help")
|
args = append(args, "help")
|
||||||
@ -49,9 +53,8 @@ func Main(args []string) (int, error) {
|
|||||||
return ExitFailure, fmt.Errorf("fatal: %s", err)
|
return ExitFailure, fmt.Errorf("fatal: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
flag.Parse()
|
command := args[i]
|
||||||
|
i++
|
||||||
command := args[1]
|
|
||||||
|
|
||||||
c := lifx.NewClient(
|
c := lifx.NewClient(
|
||||||
config.AccessToken,
|
config.AccessToken,
|
||||||
@ -61,7 +64,7 @@ func Main(args []string) (int, error) {
|
|||||||
Context := Context{
|
Context := Context{
|
||||||
Client: c,
|
Client: c,
|
||||||
Config: *config,
|
Config: *config,
|
||||||
Args: args[2:],
|
Args: args[i:],
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd, ok := GetCommand(command)
|
cmd, ok := GetCommand(command)
|
||||||
@ -72,7 +75,7 @@ func Main(args []string) (int, error) {
|
|||||||
|
|
||||||
fs := cmd.Flags
|
fs := cmd.Flags
|
||||||
if fs != nil {
|
if fs != nil {
|
||||||
fs.Parse(args[2:])
|
fs.Parse(args[i:])
|
||||||
Context.Flags = Flags{FlagSet: fs}
|
Context.Flags = Flags{FlagSet: fs}
|
||||||
}
|
}
|
||||||
Context.Name = command
|
Context.Name = command
|
||||||
|
Loading…
Reference in New Issue
Block a user