github.com/wtfutil/wtf@v0.43.0/help/help.go (about)

     1  package help
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/olebedev/config"
     7  	"github.com/wtfutil/wtf/app"
     8  	"github.com/wtfutil/wtf/utils"
     9  )
    10  
    11  // Display displays the output of the --help argument
    12  func Display(moduleName string, cfg *config.Config) {
    13  	if moduleName == "" {
    14  		fmt.Println("\n  --module takes a module name as an argument, i.e: '--module=github'")
    15  	} else {
    16  		fmt.Printf("%s\n", helpFor(moduleName, cfg))
    17  	}
    18  }
    19  
    20  func helpFor(moduleName string, cfg *config.Config) string {
    21  	err := cfg.Set("wtf.mods."+moduleName+".enabled", true)
    22  	if err != nil {
    23  		return ""
    24  	}
    25  
    26  	widget := app.MakeWidget(nil, nil, moduleName, cfg, nil)
    27  
    28  	// Since we are forcing enabled config, if no module
    29  	// exists, we will get the unknown one
    30  	if widget.CommonSettings().Title == "Unknown" {
    31  		return "Unable to find module " + moduleName
    32  	}
    33  
    34  	result := ""
    35  	result += utils.StripColorTags(widget.HelpText())
    36  	result += "\n"
    37  	result += "Configuration Attributes"
    38  	result += widget.ConfigText()
    39  	return result
    40  }