NewCmdCreate returns new initialized instance of create sub command
(f cmdutil.Factory, ioStreams genericiooptions.IOStreams)
| 100 | |
| 101 | // NewCmdCreate returns new initialized instance of create sub command |
| 102 | func 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 |
| 157 | func (o *CreateOptions) Validate() error { |
searching dependent graphs…