From 2da334461208c21ba8ce4419cfa0c753e2e7facf Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sat, 6 Jul 2019 01:55:54 -0700 Subject: [PATCH] Get --module=[modname] working again (broke when position config validation was added) --- help/help.go | 7 ++++++- maker/widget_maker.go | 1 + modules/jira/widget.go | 4 ++-- utils/help_parser.go | 15 +++++++++------ wtf/keyboard_widget.go | 1 + 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/help/help.go b/help/help.go index 9135b39b..e8f84e6c 100644 --- a/help/help.go +++ b/help/help.go @@ -8,6 +8,7 @@ import ( "github.com/wtfutil/wtf/utils" ) +// Display displays the output of the --help argument func Display(moduleName string, config *config.Config) { if moduleName == "" { fmt.Println("\n --module takes a module name as an argument, i.e: '--module=github'") @@ -17,9 +18,13 @@ func Display(moduleName string, config *config.Config) { } func helpFor(moduleName string, config *config.Config) string { - widget := maker.MakeWidget(nil, nil, moduleName, moduleName, config, config) + modConfig, _ := config.Get("wtf.mods." + moduleName) + widget := maker.MakeWidget(nil, nil, moduleName, moduleName, modConfig, config) + result := "" result += utils.StripColorTags(widget.HelpText()) + result += "\n" + result += "Configuration Attributes" result += widget.ConfigText() return result } diff --git a/maker/widget_maker.go b/maker/widget_maker.go index ad33a572..9e9e98e5 100644 --- a/maker/widget_maker.go +++ b/maker/widget_maker.go @@ -223,6 +223,7 @@ func MakeWidgets(app *tview.Application, pages *tview.Pages, config *config.Conf for mod := range mods { modConfig, _ := config.Get("wtf.mods." + mod) widgetType := modConfig.UString("type", mod) + if enabled := modConfig.UBool("enabled", false); enabled { widget := MakeWidget(app, pages, mod, widgetType, modConfig, config) widgets = append(widgets, widget) diff --git a/modules/jira/widget.go b/modules/jira/widget.go index d457259d..362e3fc1 100644 --- a/modules/jira/widget.go +++ b/modules/jira/widget.go @@ -51,8 +51,6 @@ func (widget *Widget) Refresh() { widget.Render() } -/* -------------------- Unexported Functions -------------------- */ - func (widget *Widget) Render() { if widget.result == nil { return @@ -63,6 +61,8 @@ func (widget *Widget) Render() { widget.Redraw(str, widget.contentFrom(widget.result), false) } +/* -------------------- Unexported Functions -------------------- */ + func (widget *Widget) openItem() { sel := widget.GetSelected() if sel >= 0 && widget.result != nil && sel < len(widget.result.Issues) { diff --git a/utils/help_parser.go b/utils/help_parser.go index 624d1933..7ff0b12e 100644 --- a/utils/help_parser.go +++ b/utils/help_parser.go @@ -28,20 +28,24 @@ func StripColorTags(input string) string { func helpFromValue(field reflect.StructField) string { result := "" - var help string = field.Tag.Get("help") + optional, err := strconv.ParseBool(field.Tag.Get("optional")) if err != nil { optional = false } - var values string = field.Tag.Get("values") + + help := field.Tag.Get("help") if optional { help = "Optional " + help } + + values := field.Tag.Get("values") if help != "" { - result += "\n\n" + lowercaseTitle(field.Name) - result += "\n" + help + result += "\n\n " + lowercaseTitle(field.Name) + result += "\n " + help + if values != "" { - result += "\nValues: " + values + result += "\n Values: " + values } } @@ -49,7 +53,6 @@ func helpFromValue(field reflect.StructField) string { } func HelpFromInterface(item interface{}) string { - result := "" t := reflect.TypeOf(item) diff --git a/wtf/keyboard_widget.go b/wtf/keyboard_widget.go index 8f83aba4..4ea06749 100644 --- a/wtf/keyboard_widget.go +++ b/wtf/keyboard_widget.go @@ -85,6 +85,7 @@ func (widget *KeyboardWidget) InputCapture(event *tcell.EventKey) *tcell.EventKe return event } +// HelpText returns the help text and keyboard command info for this widget func (widget *KeyboardWidget) HelpText() string { str := " [green::b]Keyboard commands for " + strings.Title(widget.settings.Module.Type) + "[white]\n\n"