-
Notifications
You must be signed in to change notification settings - Fork 20
/
template_list.go
52 lines (44 loc) · 1.08 KB
/
template_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
package cmd
import (
"os"
"strconv"
"strings"
"github.com/exoscale/cli/table"
"github.com/spf13/cobra"
)
func init() {
templateCmd.AddCommand(templateListCmd)
}
// templateListCmd represents the list command
var templateListCmd = &cobra.Command{
Use: "list [keyword]",
Short: "List all available templates",
Aliases: gListAlias,
RunE: func(cmd *cobra.Command, args []string) error {
t := table.NewTable(os.Stdout)
err := listTemplates(t, args)
if err == nil {
t.Render()
}
return err
},
}
func listTemplates(t *table.Table, filters []string) error {
zoneID, err := getZoneIDByName(gCurrentAccount.DefaultZone)
if err != nil {
return err
}
templates, err := findTemplates(zoneID, filters...)
if err != nil {
return err
}
t.SetHeader([]string{"Operating System", "Disk", "Release Date", "ID"})
for _, template := range templates {
sz := strconv.FormatInt(template.Size>>30, 10)
if sz == "10" && strings.HasPrefix(template.Name, "Linux") {
sz = ""
}
t.Append([]string{template.Name, sz, template.Created, template.ID.String()})
}
return nil
}