-
-
Notifications
You must be signed in to change notification settings - Fork 812
/
Copy pathhelp.go
40 lines (33 loc) · 980 Bytes
/
help.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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 {
err := cfg.Set("wtf.mods."+moduleName+".enabled", true)
if err != nil {
return ""
}
widget := app.MakeWidget(nil, nil, moduleName, cfg, nil)
// 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
}