1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Closes #29. wtf.go --help [module name] returns help text if any is available.

This commit is contained in:
Chris Cummer 2018-05-22 20:34:33 -07:00
parent 9e9ef9371d
commit ff49ecb082
7 changed files with 47 additions and 19 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)
}
}

View File

@ -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)

View File

@ -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)

View File

@ -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)

8
wtf.go
View File

@ -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 -------------------- */