mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Help halts the program execution
This commit is contained in:
parent
128347e513
commit
ca48d34566
30
help/help.go
30
help/help.go
@ -11,25 +11,25 @@ import (
|
|||||||
"github.com/senorprogrammer/wtf/weather"
|
"github.com/senorprogrammer/wtf/weather"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DisplayCommandInfo(args []string, version string) {
|
//func DisplayCommandInfo(args []string, version string) {
|
||||||
if len(args) == 0 {
|
//if len(args) == 0 {
|
||||||
return
|
//return
|
||||||
}
|
//}
|
||||||
|
|
||||||
cmd := args[0]
|
//cmd := args[0]
|
||||||
|
|
||||||
switch cmd {
|
//switch cmd {
|
||||||
case "help", "--help":
|
//case "help", "--help":
|
||||||
DisplayHelpInfo(args)
|
//DisplayHelpInfo(args)
|
||||||
case "version", "--version":
|
//case "version", "--version":
|
||||||
DisplayVersionInfo(version)
|
//DisplayVersionInfo(version)
|
||||||
}
|
//}
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
func DisplayHelpInfo(args []string) {
|
func DisplayHelpInfo(moduleName string) {
|
||||||
if len(args) >= 1 {
|
if moduleName != "" {
|
||||||
fmt.Printf("%s\n", helpFor(args[0]))
|
fmt.Printf("%s\n", helpFor(moduleName))
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("\n --help takes a module name as an argument, i.e: '--help github'")
|
fmt.Println("\n --help takes a module name as an argument, i.e: '--help github'")
|
||||||
}
|
}
|
||||||
|
8
wtf.go
8
wtf.go
@ -215,12 +215,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var cmdFlags struct {
|
var cmdFlags struct {
|
||||||
Version bool `short:"v" long:"version" description:"Show Version Info"`
|
|
||||||
Config string `short:"c" long:"config" optional:"yes" description:"Path to config file"`
|
Config string `short:"c" long:"config" optional:"yes" description:"Path to config file"`
|
||||||
|
Version bool `short:"v" long:"version" description:"Show Version Info"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var parser = flags.NewParser(&cmdFlags, flags.Default)
|
var parser = flags.NewParser(&cmdFlags, flags.Default)
|
||||||
parser.Parse()
|
if _, err := parser.Parse(); err != nil {
|
||||||
|
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp {
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(cmdFlags.Config) == 0 {
|
if len(cmdFlags.Config) == 0 {
|
||||||
cmdFlags.Config = filepath.Join(homeDir, ".wtf", "config.yml")
|
cmdFlags.Config = filepath.Join(homeDir, ".wtf", "config.yml")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user