-
Notifications
You must be signed in to change notification settings - Fork 23
/
app_ls.go
44 lines (37 loc) · 1.12 KB
/
app_ls.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
package cmd
import (
"strings"
"github.com/pkg/errors"
"github.com/replicatedhq/replicated/cli/print"
"github.com/replicatedhq/replicated/pkg/types"
"github.com/spf13/cobra"
)
func (r *runners) InitAppList(parent *cobra.Command) *cobra.Command {
cmd := &cobra.Command{
Use: "ls [NAME]",
Short: "list kots apps",
Long: `list kots apps, or a single app by name`,
RunE: r.listApps,
SilenceUsage: true,
}
parent.AddCommand(cmd)
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")
return cmd
}
func (r *runners) listApps(_ *cobra.Command, args []string) error {
kotsApps, err := r.kotsAPI.ListApps()
if err != nil {
return errors.Wrap(err, "list apps")
}
if len(args) == 0 {
return print.Apps(r.outputFormat, r.w, kotsApps)
}
appSearch := args[0]
var resultApps []types.AppAndChannels
for _, app := range kotsApps {
if strings.Contains(app.App.ID, appSearch) || strings.Contains(app.App.Slug, appSearch) {
resultApps = append(resultApps, app)
}
}
return print.Apps(r.outputFormat, r.w, resultApps)
}