/
list.go
66 lines (54 loc) · 1.44 KB
/
list.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package command
import (
"bytes"
"fmt"
"strings"
"github.com/olekukonko/tablewriter"
"github.com/tcnksm/gcli/skeleton"
)
// ListCommand is a Command that lists all avairable frameworks
type ListCommand struct {
Meta
}
// Run lists all avairable frameworks.
func (c *ListCommand) Run(args []string) int {
uflag := c.Meta.NewFlagSet("list", c.Help())
if err := uflag.Parse(args); err != nil {
return 1
}
outBuffer := new(bytes.Buffer)
// Create a table for output
table := tablewriter.NewWriter(outBuffer)
header := []string{"Name", "Command", "URL"}
table.SetHeader(header)
for _, f := range skeleton.Frameworks {
if f.Hide {
continue
}
var cmd string
if len(f.CommandTemplates) > 0 {
cmd = "*"
}
table.Append([]string{f.Name, cmd, f.URL})
}
// Write a table
table.Render()
fmt.Fprintf(outBuffer, "COMMAND(*) means you can create command pattern CLI with that framework (you can use --command flag)")
c.UI.Output(outBuffer.String())
return 0
}
// Synopsis is a one-line, short synopsis of the command.
func (c *ListCommand) Synopsis() string {
return "List available cli frameworks"
}
// Help is a long-form help text that includes the command-line
// usage, a brief few sentences explaining the function of the command,
// and the complete list of flags the command accepts.
func (c *ListCommand) Help() string {
helpText := `
Show all avairable cli frameworks.
Usage:
gcli list
`
return strings.TrimSpace(helpText)
}