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

Get --module=[modname] working again (broke when position config validation was added)

This commit is contained in:
Chris Cummer 2019-07-06 01:55:54 -07:00
parent 2b2cdf912b
commit 2da3344612
5 changed files with 19 additions and 9 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/utils"
) )
// Display displays the output of the --help argument
func Display(moduleName string, config *config.Config) { func Display(moduleName string, config *config.Config) {
if moduleName == "" { if moduleName == "" {
fmt.Println("\n --module takes a module name as an argument, i.e: '--module=github'") 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 { 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 := ""
result += utils.StripColorTags(widget.HelpText()) result += utils.StripColorTags(widget.HelpText())
result += "\n"
result += "Configuration Attributes"
result += widget.ConfigText() result += widget.ConfigText()
return result return result
} }

View File

@ -223,6 +223,7 @@ func MakeWidgets(app *tview.Application, pages *tview.Pages, config *config.Conf
for mod := range mods { for mod := range mods {
modConfig, _ := config.Get("wtf.mods." + mod) modConfig, _ := config.Get("wtf.mods." + mod)
widgetType := modConfig.UString("type", mod) widgetType := modConfig.UString("type", mod)
if enabled := modConfig.UBool("enabled", false); enabled { if enabled := modConfig.UBool("enabled", false); enabled {
widget := MakeWidget(app, pages, mod, widgetType, modConfig, config) widget := MakeWidget(app, pages, mod, widgetType, modConfig, config)
widgets = append(widgets, widget) widgets = append(widgets, widget)

View File

@ -51,8 +51,6 @@ func (widget *Widget) Refresh() {
widget.Render() widget.Render()
} }
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) Render() { func (widget *Widget) Render() {
if widget.result == nil { if widget.result == nil {
return return
@ -63,6 +61,8 @@ func (widget *Widget) Render() {
widget.Redraw(str, widget.contentFrom(widget.result), false) widget.Redraw(str, widget.contentFrom(widget.result), false)
} }
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) openItem() { func (widget *Widget) openItem() {
sel := widget.GetSelected() sel := widget.GetSelected()
if sel >= 0 && widget.result != nil && sel < len(widget.result.Issues) { if sel >= 0 && widget.result != nil && sel < len(widget.result.Issues) {

View File

@ -28,18 +28,22 @@ func StripColorTags(input string) string {
func helpFromValue(field reflect.StructField) string { func helpFromValue(field reflect.StructField) string {
result := "" result := ""
var help string = field.Tag.Get("help")
optional, err := strconv.ParseBool(field.Tag.Get("optional")) optional, err := strconv.ParseBool(field.Tag.Get("optional"))
if err != nil { if err != nil {
optional = false optional = false
} }
var values string = field.Tag.Get("values")
help := field.Tag.Get("help")
if optional { if optional {
help = "Optional " + help help = "Optional " + help
} }
values := field.Tag.Get("values")
if help != "" { if help != "" {
result += "\n\n " + lowercaseTitle(field.Name) result += "\n\n " + lowercaseTitle(field.Name)
result += "\n " + help result += "\n " + help
if values != "" { if values != "" {
result += "\n Values: " + values result += "\n Values: " + values
} }
@ -49,7 +53,6 @@ func helpFromValue(field reflect.StructField) string {
} }
func HelpFromInterface(item interface{}) string { func HelpFromInterface(item interface{}) string {
result := "" result := ""
t := reflect.TypeOf(item) t := reflect.TypeOf(item)

View File

@ -85,6 +85,7 @@ func (widget *KeyboardWidget) InputCapture(event *tcell.EventKey) *tcell.EventKe
return event return event
} }
// HelpText returns the help text and keyboard command info for this widget
func (widget *KeyboardWidget) HelpText() string { func (widget *KeyboardWidget) HelpText() string {
str := " [green::b]Keyboard commands for " + strings.Title(widget.settings.Module.Type) + "[white]\n\n" str := " [green::b]Keyboard commands for " + strings.Title(widget.settings.Module.Type) + "[white]\n\n"