Compare commits
2 Commits
5b17adb071
...
518e304948
Author | SHA1 | Date | |
---|---|---|---|
518e304948 | |||
78c7572139 |
10
Makefile
10
Makefile
@ -12,14 +12,14 @@ else
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
LUME_VERSION ?= $(shell git describe --tags --always)
|
LUME_VERSION ?= $(shell git describe --tags --always)
|
||||||
LDFLAGS := ${LDFLAGS} \
|
LDFLAGS := $(LDFLAGS) \
|
||||||
-X git.kill0.net/chill9/lume/cmd.Version=${LUME_VERSION} \
|
-X git.kill0.net/chill9/lume/cmd.Version=$(LUME_VERSION) \
|
||||||
-X git.kill0.net/chill9/lume/cmd.BuildDate=${BUILD_DATE}
|
-X git.kill0.net/chill9/lume/cmd.BuildDate=$(BUILD_DATE)
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build:
|
build:
|
||||||
$(Q) go build -o ${EXE} -ldflags="${LDFLAGS}" ./cmd/lume
|
$(Q) go build -o $(EXE) -ldflags="$(LDFLAGS)" ./cmd/lume
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
${RM} ${EXE}
|
$(RM) $(EXE)
|
@ -21,6 +21,7 @@ type Config struct {
|
|||||||
|
|
||||||
type CmdArgs struct {
|
type CmdArgs struct {
|
||||||
Flags Flags
|
Flags Flags
|
||||||
|
Args []string
|
||||||
Client *lifx.Client
|
Client *lifx.Client
|
||||||
Config Config
|
Config Config
|
||||||
Name string
|
Name string
|
||||||
|
20
cmd/help.go
20
cmd/help.go
@ -1,7 +1,6 @@
|
|||||||
package lumecmd
|
package lumecmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
@ -10,23 +9,16 @@ func NewCmdHelp() Command {
|
|||||||
return Command{
|
return Command{
|
||||||
Name: "help",
|
Name: "help",
|
||||||
Func: HelpCmd,
|
Func: HelpCmd,
|
||||||
Flags: func() *flag.FlagSet {
|
|
||||||
fs := flag.NewFlagSet("help", flag.ExitOnError)
|
|
||||||
|
|
||||||
return fs
|
|
||||||
}(),
|
|
||||||
Use: "<command>",
|
Use: "<command>",
|
||||||
Short: "Show help for a command",
|
Short: "Show help for a command",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HelpCmd(args CmdArgs) (int, error) {
|
func HelpCmd(args CmdArgs) (int, error) {
|
||||||
argv := args.Flags.Args()
|
if len(args.Args) == 0 {
|
||||||
|
|
||||||
if len(argv) == 0 {
|
|
||||||
printHelp(commandRegistry)
|
printHelp(commandRegistry)
|
||||||
} else if len(argv) >= 1 {
|
} else if len(args.Args) >= 1 {
|
||||||
printCmdHelp(argv[0])
|
printCmdHelp(args.Args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
return ExitSuccess, nil
|
return ExitSuccess, nil
|
||||||
@ -63,11 +55,15 @@ func printCmdHelp(name string) error {
|
|||||||
|
|
||||||
if subCmd.Use != "" {
|
if subCmd.Use != "" {
|
||||||
fmt.Printf("usage:\n lume %s %s\n", subCmd.Name, subCmd.Use)
|
fmt.Printf("usage:\n lume %s %s\n", subCmd.Name, subCmd.Use)
|
||||||
fmt.Println()
|
} else {
|
||||||
|
fmt.Printf("usage:\n lume %s\n", subCmd.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if subCmd.Flags != nil {
|
||||||
|
fmt.Println()
|
||||||
fmt.Print("flags:\n")
|
fmt.Print("flags:\n")
|
||||||
subCmd.Flags.PrintDefaults()
|
subCmd.Flags.PrintDefaults()
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,7 @@ func Main(args []string) (int, error) {
|
|||||||
cmdArgs := CmdArgs{
|
cmdArgs := CmdArgs{
|
||||||
Client: c,
|
Client: c,
|
||||||
Config: config,
|
Config: config,
|
||||||
|
Args: args[2:],
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd, ok := GetCommand(command)
|
cmd, ok := GetCommand(command)
|
||||||
@ -81,11 +82,14 @@ func Main(args []string) (int, error) {
|
|||||||
err = fmt.Errorf("lume: '%s' is not lume command. See 'lume help'", command)
|
err = fmt.Errorf("lume: '%s' is not lume command. See 'lume help'", command)
|
||||||
return ExitFailure, err
|
return ExitFailure, err
|
||||||
}
|
}
|
||||||
fs := cmd.Flags
|
|
||||||
fs.Parse(args[2:])
|
|
||||||
|
|
||||||
|
fs := cmd.Flags
|
||||||
|
if fs != nil {
|
||||||
|
fs.Parse(args[2:])
|
||||||
cmdArgs.Flags = Flags{FlagSet: fs}
|
cmdArgs.Flags = Flags{FlagSet: fs}
|
||||||
|
}
|
||||||
cmdArgs.Name = command
|
cmdArgs.Name = command
|
||||||
|
|
||||||
exitCode, err := cmd.Func(cmdArgs)
|
exitCode, err := cmd.Func(cmdArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("fatal: %s", err)
|
err = fmt.Errorf("fatal: %s", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user