-
Notifications
You must be signed in to change notification settings - Fork 62
/
cmd.go
56 lines (45 loc) · 1.58 KB
/
cmd.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
// Copyright Contributors to the Open Cluster Management project
package sampleapp
import (
"fmt"
genericclioptionsclusteradm "open-cluster-management.io/clusteradm/pkg/genericclioptions"
clusteradmhelpers "open-cluster-management.io/clusteradm/pkg/helpers"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
)
var example = `
# Create a sample app
%[1]s create sampleapp sampleapp1
# Create a sample app on specified namespace
%[1]s create sampleapp sampleapp1 --namespace namespace1
`
// NewCmd...
func NewCmd(clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags, streams genericclioptions.IOStreams) *cobra.Command {
o := NewOptions(clusteradmFlags, streams)
cmd := &cobra.Command{
Use: "sampleapp",
Short: "Create a sample app",
Long: "Create a sample app, by generating Helm ngix deployment yamls",
Example: fmt.Sprintf(example, clusteradmhelpers.GetExampleHeader()),
SilenceUsage: true,
PreRunE: func(c *cobra.Command, args []string) error {
clusteradmhelpers.DryRunMessage(clusteradmFlags.DryRun)
return nil
},
RunE: func(c *cobra.Command, args []string) error {
if err := o.complete(c, args); err != nil {
return err
}
if err := o.Validate(); err != nil {
return err
}
if err := o.Run(); err != nil {
return err
}
return nil
},
}
cmd.Flags().StringVar(&o.OutputFile, "output-file", "", "The generated resources will be copied in the specified file")
cmd.Flags().StringVarP(&o.Namespace, "namespace", "n", "default", "Specified namespace to deploy sample app")
return cmd
}