-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_bootstrap_project_template.go
72 lines (56 loc) · 1.86 KB
/
create_bootstrap_project_template.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package admin
import (
"errors"
"io"
"github.com/spf13/cobra"
cmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
"github.com/openshift/origin/pkg/project/registry/projectrequest/delegated"
templateapi "github.com/openshift/origin/pkg/template/api"
)
const CreateBootstrapProjectTemplateCommand = "create-bootstrap-project-template"
type CreateBootstrapProjectTemplateOptions struct {
Name string
}
func NewCommandCreateBootstrapProjectTemplate(f *clientcmd.Factory, commandName string, fullName string, out io.Writer) *cobra.Command {
options := &CreateBootstrapProjectTemplateOptions{}
cmd := &cobra.Command{
Use: commandName,
Short: "Create bootstrap project template for OpenShift",
Run: func(cmd *cobra.Command, args []string) {
if err := options.Validate(args); err != nil {
cmdutil.CheckErr(cmdutil.UsageError(cmd, err.Error()))
}
template, err := options.CreateBootstrapProjectTemplate()
if err != nil {
cmdutil.CheckErr(err)
}
err = f.Factory.PrintObject(cmd, template, out)
if err != nil {
cmdutil.CheckErr(err)
}
},
}
cmd.SetOutput(out)
cmd.Flags().StringVar(&options.Name, "name", delegated.DefaultTemplateName, "The name of the template to output.")
cmdutil.AddPrinterFlags(cmd)
// Default to JSON
if flag := cmd.Flags().Lookup("output"); flag != nil {
flag.Value.Set("json")
}
return cmd
}
func (o CreateBootstrapProjectTemplateOptions) Validate(args []string) error {
if len(args) != 0 {
return errors.New("no arguments are supported")
}
if len(o.Name) == 0 {
return errors.New("--name must be provided")
}
return nil
}
func (o CreateBootstrapProjectTemplateOptions) CreateBootstrapProjectTemplate() (*templateapi.Template, error) {
template := delegated.DefaultTemplate()
template.Name = o.Name
return template, nil
}