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