1
0
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:
Chris Cummer 2018-05-29 16:39:24 -07:00
parent 128347e513
commit ca48d34566
2 changed files with 21 additions and 17 deletions

View File

@ -11,25 +11,25 @@ import (
"github.com/senorprogrammer/wtf/weather"
)
func DisplayCommandInfo(args []string, version string) {
if len(args) == 0 {
return
}
//func DisplayCommandInfo(args []string, version string) {
//if len(args) == 0 {
//return
//}
cmd := args[0]
//cmd := args[0]
switch cmd {
case "help", "--help":
DisplayHelpInfo(args)
case "version", "--version":
DisplayVersionInfo(version)
}
//switch cmd {
//case "help", "--help":
//DisplayHelpInfo(args)
//case "version", "--version":
//DisplayVersionInfo(version)
//}
}
//}
func DisplayHelpInfo(args []string) {
if len(args) >= 1 {
fmt.Printf("%s\n", helpFor(args[0]))
func DisplayHelpInfo(moduleName string) {
if moduleName != "" {
fmt.Printf("%s\n", helpFor(moduleName))
} else {
fmt.Println("\n --help takes a module name as an argument, i.e: '--help github'")
}

8
wtf.go
View File

@ -215,12 +215,16 @@ func main() {
}
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"`
Version bool `short:"v" long:"version" description:"Show Version Info"`
}
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 {
cmdFlags.Config = filepath.Join(homeDir, ".wtf", "config.yml")