MCPcopy
hub / github.com/kubernetes/kubectl / NewCmdCreate

Function NewCmdCreate

pkg/cmd/create/create.go:102–154  ·  view source on GitHub ↗

NewCmdCreate returns new initialized instance of create sub command

(f cmdutil.Factory, ioStreams genericiooptions.IOStreams)

Source from the content-addressed store, hash-verified

100
101// NewCmdCreate returns new initialized instance of create sub command
102func NewCmdCreate(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
103 o := NewCreateOptions(ioStreams)
104
105 cmd := &cobra.Command{
106 Use: "create -f FILENAME",
107 DisableFlagsInUseLine: true,
108 Short: i18n.T("Create a resource from a file or from stdin"),
109 Long: createLong,
110 Example: createExample,
111 Run: func(cmd *cobra.Command, args []string) {
112 cmdutil.CheckErr(o.Complete(f, cmd, args))
113 cmdutil.CheckErr(o.Validate())
114 cmdutil.CheckErr(o.RunCreate(f, cmd))
115 },
116 }
117
118 // bind flag structs
119 o.RecordFlags.AddFlags(cmd)
120
121 usage := "to use to create the resource"
122 cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, usage)
123 cmdutil.AddValidateFlags(cmd)
124 cmd.Flags().BoolVar(&o.EditBeforeCreate, "edit", o.EditBeforeCreate, "Edit the API resource before creating")
125 cmd.Flags().Bool("windows-line-endings", runtime.GOOS == "windows",
126 "Only relevant if --edit=true. Defaults to the line ending native to your platform.")
127 cmdutil.AddApplyAnnotationFlags(cmd)
128 cmdutil.AddDryRunFlag(cmd)
129 cmdutil.AddLabelSelectorFlagVar(cmd, &o.Selector)
130 cmd.Flags().StringVar(&o.Raw, "raw", o.Raw, "Raw URI to POST to the server. Uses the transport specified by the kubeconfig file.")
131 cmdutil.AddFieldManagerFlagVar(cmd, &o.fieldManager, "kubectl-create")
132
133 o.PrintFlags.AddFlags(cmd)
134
135 // create subcommands
136 cmd.AddCommand(NewCmdCreateNamespace(f, ioStreams))
137 cmd.AddCommand(NewCmdCreateQuota(f, ioStreams))
138 cmd.AddCommand(NewCmdCreateSecret(f, ioStreams))
139 cmd.AddCommand(NewCmdCreateConfigMap(f, ioStreams))
140 cmd.AddCommand(NewCmdCreateServiceAccount(f, ioStreams))
141 cmd.AddCommand(NewCmdCreateService(f, ioStreams))
142 cmd.AddCommand(NewCmdCreateDeployment(f, ioStreams))
143 cmd.AddCommand(NewCmdCreateClusterRole(f, ioStreams))
144 cmd.AddCommand(NewCmdCreateClusterRoleBinding(f, ioStreams))
145 cmd.AddCommand(NewCmdCreateRole(f, ioStreams))
146 cmd.AddCommand(NewCmdCreateRoleBinding(f, ioStreams))
147 cmd.AddCommand(NewCmdCreatePodDisruptionBudget(f, ioStreams))
148 cmd.AddCommand(NewCmdCreatePriorityClass(f, ioStreams))
149 cmd.AddCommand(NewCmdCreateJob(f, ioStreams))
150 cmd.AddCommand(NewCmdCreateCronJob(f, ioStreams))
151 cmd.AddCommand(NewCmdCreateIngress(f, ioStreams))
152 cmd.AddCommand(NewCmdCreateToken(f, ioStreams))
153 return cmd
154}
155
156// Validate makes sure there is no discrepancy in command options
157func (o *CreateOptions) Validate() error {

Callers 7

NewKubectlCommandFunction · 0.92
TestEditFunction · 0.92
TestExtraArgsFailFunction · 0.85
TestCreateObjectFunction · 0.85
TestCreateMultipleObjectFunction · 0.85
TestCreateDirectoryFunction · 0.85
TestMissingFilenameErrorFunction · 0.85

Calls 15

CompleteMethod · 0.95
ValidateMethod · 0.95
RunCreateMethod · 0.95
TFunction · 0.92
NewCreateOptionsFunction · 0.85
NewCmdCreateNamespaceFunction · 0.85
NewCmdCreateQuotaFunction · 0.85
NewCmdCreateSecretFunction · 0.85
NewCmdCreateConfigMapFunction · 0.85
NewCmdCreateServiceFunction · 0.85
NewCmdCreateDeploymentFunction · 0.85

Tested by 6

TestEditFunction · 0.74
TestExtraArgsFailFunction · 0.68
TestCreateObjectFunction · 0.68
TestCreateMultipleObjectFunction · 0.68
TestCreateDirectoryFunction · 0.68
TestMissingFilenameErrorFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…