-
Notifications
You must be signed in to change notification settings - Fork 688
Expand file tree
/
Copy pathlist.go
More file actions
52 lines (42 loc) · 916 Bytes
/
list.go
File metadata and controls
52 lines (42 loc) · 916 Bytes
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 cli
import (
"fmt"
"os"
"sort"
"text/tabwriter"
"github.com/spf13/cobra"
"github.com/xeonx/timeago"
"github.com/replicate/cog/pkg/client"
)
func newListCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List Cog models",
RunE: listModels,
Args: cobra.NoArgs,
Aliases: []string{"ls"},
}
addRepoFlag(cmd)
return cmd
}
func listModels(cmd *cobra.Command, args []string) error {
repo, err := getRepo()
if err != nil {
return err
}
cli := client.NewClient()
models, err := cli.ListModels(repo)
if err != nil {
return err
}
sort.Slice(models, func(i, j int) bool {
return models[i].Created.After(models[j].Created)
})
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
fmt.Fprintln(w, "ID\tCREATED")
for _, mod := range models {
fmt.Fprintf(w, "%s\t%s\n", mod.ID, timeago.English.Format(mod.Created))
}
w.Flush()
return nil
}