1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/help/help.go
Sean Smith f28605cdf8 Fix help for modules
This does 2 things:
1. Forces a module to be 'enabled' on the help route, so that it works
2. Better handling when no module is actually found
2019-08-11 21:49:01 -04:00

37 lines
935 B
Go

package help
import (
"fmt"
"github.com/olebedev/config"
"github.com/wtfutil/wtf/app"
"github.com/wtfutil/wtf/utils"
)
// Display displays the output of the --help argument
func Display(moduleName string, cfg *config.Config) {
if moduleName == "" {
fmt.Println("\n --module takes a module name as an argument, i.e: '--module=github'")
} else {
fmt.Printf("%s\n", helpFor(moduleName, cfg))
}
}
func helpFor(moduleName string, cfg *config.Config) string {
cfg.Set("wtf.mods."+moduleName+".enabled", true)
widget := app.MakeWidget(nil, nil, moduleName, cfg)
// Since we are forcing enabled config, if no module
// exists, we will get the unknown one
if widget.CommonSettings().Title == "Unknown" {
return "Unable to find module " + moduleName
}
result := ""
result += utils.StripColorTags(widget.HelpText())
result += "\n"
result += "Configuration Attributes"
result += widget.ConfigText()
return result
}