github.com/tcnksm/gcli@v0.2.4-0.20170129033839-7eb950507e5a/command/list.go (about) 1 package command 2 3 import ( 4 "bytes" 5 "fmt" 6 "strings" 7 8 "github.com/olekukonko/tablewriter" 9 "github.com/tcnksm/gcli/skeleton" 10 ) 11 12 // ListCommand is a Command that lists all avairable frameworks 13 type ListCommand struct { 14 Meta 15 } 16 17 // Run lists all avairable frameworks. 18 func (c *ListCommand) Run(args []string) int { 19 20 uflag := c.Meta.NewFlagSet("list", c.Help()) 21 if err := uflag.Parse(args); err != nil { 22 return 1 23 } 24 25 outBuffer := new(bytes.Buffer) 26 // Create a table for output 27 table := tablewriter.NewWriter(outBuffer) 28 header := []string{"Name", "Command", "URL"} 29 table.SetHeader(header) 30 for _, f := range skeleton.Frameworks { 31 if f.Hide { 32 continue 33 } 34 var cmd string 35 if len(f.CommandTemplates) > 0 { 36 cmd = "*" 37 } 38 table.Append([]string{f.Name, cmd, f.URL}) 39 } 40 41 // Write a table 42 table.Render() 43 44 fmt.Fprintf(outBuffer, "COMMAND(*) means you can create command pattern CLI with that framework (you can use --command flag)") 45 c.UI.Output(outBuffer.String()) 46 return 0 47 } 48 49 // Synopsis is a one-line, short synopsis of the command. 50 func (c *ListCommand) Synopsis() string { 51 return "List available cli frameworks" 52 } 53 54 // Help is a long-form help text that includes the command-line 55 // usage, a brief few sentences explaining the function of the command, 56 // and the complete list of flags the command accepts. 57 func (c *ListCommand) Help() string { 58 helpText := ` 59 Show all avairable cli frameworks. 60 61 Usage: 62 63 gcli list 64 ` 65 return strings.TrimSpace(helpText) 66 }