github.com/wawandco/oxpecker@v1.5.7-0.20210910201653-5958d4afdd89/tools/cli/help/toplevel.go (about)

     1  package help
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"text/tabwriter"
     7  
     8  	"github.com/wawandco/oxpecker/plugins"
     9  )
    10  
    11  // printTopLevel prints the top level help text with a table that contains top level
    12  // commands (names) and descriptions.
    13  func (h *Command) printTopLevel() {
    14  	fmt.Printf("Oxpecker allows to build apps with ease\n\n")
    15  	fmt.Println("Usage:")
    16  	fmt.Printf("  ox [command]\n\n")
    17  
    18  	w := new(tabwriter.Writer)
    19  	defer w.Flush()
    20  
    21  	// minwidth, tabwidth, padding, padchar, flags
    22  	w.Init(os.Stdout, 8, 8, 3, '\t', 0)
    23  	fmt.Println("Commands:")
    24  	fmt.Println("Command\t     Alias")
    25  
    26  	for _, plugin := range h.commands {
    27  		helpText := ""
    28  		if ht, ok := plugin.(plugins.HelpTexter); ok {
    29  			helpText = ht.HelpText()
    30  		}
    31  
    32  		if p, ok := plugin.(plugins.Aliaser); ok {
    33  			fmt.Fprintf(w, "  %v\t%v\t%v\n", plugin.Name(), p.Alias(), helpText)
    34  		} else {
    35  			fmt.Fprintf(w, "  %v\t\t%v\n", plugin.Name(), helpText)
    36  		}
    37  	}
    38  
    39  }