/
app_create.go
50 lines (42 loc) · 1.17 KB
/
app_create.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
package cmd
import (
"github.com/pkg/errors"
"github.com/replicatedhq/replicated/cli/print"
"github.com/replicatedhq/replicated/pkg/kotsclient"
"github.com/replicatedhq/replicated/pkg/types"
"github.com/spf13/cobra"
)
func (r *runners) InitAppCreate(parent *cobra.Command) *cobra.Command {
cmd := &cobra.Command{
Use: "create NAME",
Short: "create kots apps",
Long: `create kots apps`,
RunE: r.createApp,
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) createApp(_ *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("missing app name")
}
appName := args[0]
kotsRestClient := kotsclient.VendorV3Client{HTTPClient: *r.platformAPI}
app, err := kotsRestClient.CreateKOTSApp(appName)
if err != nil {
return errors.Wrap(err, "create app")
}
apps := []types.AppAndChannels{
{
App: &types.App{
ID: app.Id,
Name: app.Name,
Slug: app.Slug,
Scheduler: "kots",
},
},
}
return print.Apps(r.outputFormat, r.w, apps)
}