github.com/goonzoid/gcli@v0.2.3-0.20150926213610-155587606ea1/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  	if len(args) > 0 {
    21  		msg := fmt.Sprintf("Invalid arguments: %s", strings.Join(args, " "))
    22  		c.UI.Error(msg)
    23  		return 1
    24  	}
    25  
    26  	outBuffer := new(bytes.Buffer)
    27  	// Create a table for output
    28  	table := tablewriter.NewWriter(outBuffer)
    29  	header := []string{"Name", "Command", "URL"}
    30  	table.SetHeader(header)
    31  	for _, f := range skeleton.Frameworks {
    32  		if f.Hide {
    33  			continue
    34  		}
    35  		var cmd string
    36  		if len(f.CommandTemplates) > 0 {
    37  			cmd = "*"
    38  		}
    39  		table.Append([]string{f.Name, cmd, f.URL})
    40  	}
    41  
    42  	// Write a table
    43  	table.Render()
    44  
    45  	fmt.Fprintf(outBuffer, "COMMAND(*) means you can create command pattern CLI with that framework (you can use --command flag)")
    46  	c.UI.Output(outBuffer.String())
    47  	return 0
    48  }
    49  
    50  // Synopsis is a one-line, short synopsis of the command.
    51  func (c *ListCommand) Synopsis() string {
    52  	return "List available cli frameworks"
    53  }
    54  
    55  // Help is a long-form help text that includes the command-line
    56  // usage, a brief few sentences explaining the function of the command,
    57  // and the complete list of flags the command accepts.
    58  func (c *ListCommand) Help() string {
    59  	helpText := `
    60  Usage: gcli list
    61  
    62    Show all avairable cli frameworks. 
    63  `
    64  	return strings.TrimSpace(helpText)
    65  }