From ff49ecb082d8d450ebb2559d65f08447a1fa83e2 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Tue, 22 May 2018 20:34:33 -0700 Subject: [PATCH] Closes #29. wtf.go --help [module name] returns help text if any is available. --- git/widget.go | 4 ++-- github/widget.go | 4 ++-- help/help.go | 34 +++++++++++++++++++++++++++++++--- textfile/widget.go | 4 ++-- todo/widget.go | 4 ++-- weather/widget.go | 8 ++++---- wtf.go | 8 ++++---- 7 files changed, 47 insertions(+), 19 deletions(-) diff --git a/git/widget.go b/git/widget.go index aa822106..f7b3edd2 100644 --- a/git/widget.go +++ b/git/widget.go @@ -10,7 +10,7 @@ import ( // Config is a pointer to the global config object var Config *config.Config -const helpText = ` +const HelpText = ` Keyboard commands for Git: /: Show/hide this help window @@ -132,7 +132,7 @@ func (widget *Widget) showHelp() { widget.app.SetFocus(widget.View) } - modal := wtf.NewBillboardModal(helpText, closeFunc) + modal := wtf.NewBillboardModal(HelpText, closeFunc) widget.pages.AddPage("help", modal, false, true) widget.app.SetFocus(modal) diff --git a/github/widget.go b/github/widget.go index ed430099..2ff10861 100644 --- a/github/widget.go +++ b/github/widget.go @@ -10,7 +10,7 @@ import ( // Config is a pointer to the global config object var Config *config.Config -const helpText = ` +const HelpText = ` Keyboard commands for Github: /: Show/hide this help window @@ -135,7 +135,7 @@ func (widget *Widget) showHelp() { widget.app.SetFocus(widget.View) } - modal := wtf.NewBillboardModal(helpText, closeFunc) + modal := wtf.NewBillboardModal(HelpText, closeFunc) widget.pages.AddPage("help", modal, false, true) widget.app.SetFocus(modal) diff --git a/help/help.go b/help/help.go index 7685f389..31f03278 100644 --- a/help/help.go +++ b/help/help.go @@ -3,6 +3,12 @@ package help import ( "fmt" "os" + + "github.com/senorprogrammer/wtf/git" + "github.com/senorprogrammer/wtf/github" + "github.com/senorprogrammer/wtf/textfile" + "github.com/senorprogrammer/wtf/todo" + "github.com/senorprogrammer/wtf/weather" ) func DisplayCommandInfo(args []string, version string) { @@ -14,15 +20,20 @@ func DisplayCommandInfo(args []string, version string) { switch cmd { case "help", "--help": - DisplayHelpInfo() + DisplayHelpInfo(args) case "version", "--version": DisplayVersionInfo(version) } } -func DisplayHelpInfo() { - fmt.Println("Help is coming...") +func DisplayHelpInfo(args []string) { + if len(args) >= 1 { + fmt.Printf("%s\n", helpFor(args[0])) + } else { + fmt.Println("\n --help takes a module name as an argument, i.e: '--help github'") + } + os.Exit(0) } @@ -30,3 +41,20 @@ func DisplayVersionInfo(version string) { fmt.Printf("Version: %s\n", version) os.Exit(0) } + +func helpFor(moduleName string) string { + switch moduleName { + case "git": + return git.HelpText + case "github": + return github.HelpText + case "textfile": + return textfile.HelpText + case "todo": + return todo.HelpText + case "weather": + return weather.HelpText + default: + return fmt.Sprintf("\n There is no help available for '%s'", moduleName) + } +} diff --git a/textfile/widget.go b/textfile/widget.go index 23023945..e452c0d7 100644 --- a/textfile/widget.go +++ b/textfile/widget.go @@ -13,7 +13,7 @@ import ( // Config is a pointer to the global config object var Config *config.Config -const helpText = ` +const HelpText = ` Keyboard commands for Textfile: /: Show/hide this help window @@ -91,7 +91,7 @@ func (widget *Widget) showHelp() { widget.app.SetFocus(widget.View) } - modal := wtf.NewBillboardModal(helpText, closeFunc) + modal := wtf.NewBillboardModal(HelpText, closeFunc) widget.pages.AddPage("help", modal, false, true) widget.app.SetFocus(modal) diff --git a/todo/widget.go b/todo/widget.go index 3e769c57..dfee992f 100644 --- a/todo/widget.go +++ b/todo/widget.go @@ -14,7 +14,7 @@ import ( // Config is a pointer to the global config object var Config *config.Config -const helpText = ` +const HelpText = ` Keyboard commands for Todo: /: Show/hide this help window @@ -221,7 +221,7 @@ func (widget *Widget) showHelp() { widget.app.SetFocus(widget.View) } - modal := wtf.NewBillboardModal(helpText, closeFunc) + modal := wtf.NewBillboardModal(HelpText, closeFunc) widget.pages.AddPage("help", modal, false, true) widget.app.SetFocus(modal) diff --git a/weather/widget.go b/weather/widget.go index 4d85ba12..05382bce 100644 --- a/weather/widget.go +++ b/weather/widget.go @@ -13,12 +13,12 @@ import ( // Config is a pointer to the global config object. var Config *config.Config -const helpText = ` +const HelpText = ` Keyboard commands for Weather: /: Show/hide this help window - h: Previous weather location - l: Next weather location + h: Previous weather location + l: Next weather location arrow left: Previous weather location arrow right: Next weather location @@ -244,7 +244,7 @@ func (widget *Widget) showHelp() { widget.app.SetFocus(widget.View) } - modal := wtf.NewBillboardModal(helpText, closeFunc) + modal := wtf.NewBillboardModal(HelpText, closeFunc) widget.pages.AddPage("help", modal, false, true) widget.app.SetFocus(modal) diff --git a/wtf.go b/wtf.go index 8f3157b8..b58d5b94 100644 --- a/wtf.go +++ b/wtf.go @@ -119,8 +119,8 @@ func main() { /* This allows the user to pass flags in however they prefer. It supports the likes of: - wtf help | -help | --help - wtf version | -version | --version + wtf -help | --help + wtf -version | --version */ flagConf := flag.String("config", "~/.wtf/config.yml", "Path to config file") flagHelp := flag.Bool("help", false, "Show help") @@ -129,14 +129,14 @@ func main() { flag.Parse() if *flagHelp { - help.DisplayHelpInfo() + help.DisplayHelpInfo(flag.Args()) } if *flagVers { help.DisplayVersionInfo(version) } - help.DisplayCommandInfo(flag.Args(), version) + //help.DisplayCommandInfo(flag.Args(), version) /* -------------------- end flag parsing and handling -------------------- */