fix error binding of edit output format

pull/8/head
Chao Wang 2018-07-16 14:27:20 +08:00
parent b883f4cff8
commit a87b82c0ad
3 changed files with 8 additions and 10 deletions

View File

@ -76,10 +76,10 @@ func NewCmdApplyEditLastApplied(f cmdutil.Factory, ioStreams genericclioptions.I
// bind flag structs
o.RecordFlags.AddFlags(cmd)
o.PrintFlags.AddFlags(cmd)
usage := "to use to edit the resource"
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, usage)
cmd.Flags().StringVarP(&o.Output, "output", "o", o.Output, "Output format. One of: yaml|json.")
cmd.Flags().BoolVar(&o.WindowsLineEndings, "windows-line-endings", o.WindowsLineEndings,
"Defaults to the line ending native to your platform.")
cmdutil.AddIncludeUninitializedFlag(cmd)

View File

@ -209,7 +209,7 @@ func (o *CreateOptions) RunCreate(f cmdutil.Factory, cmd *cobra.Command) error {
}
if o.EditBeforeCreate {
return RunEditOnCreate(f, o.RecordFlags, o.IOStreams, cmd, &o.FilenameOptions)
return RunEditOnCreate(f, o.PrintFlags, o.RecordFlags, o.IOStreams, cmd, &o.FilenameOptions)
}
schema, err := f.Validator(cmdutil.GetFlagBool(cmd, "validate"))
if err != nil {
@ -298,13 +298,13 @@ func (o *CreateOptions) raw(f cmdutil.Factory) error {
return nil
}
func RunEditOnCreate(f cmdutil.Factory, recordFlags *genericclioptions.RecordFlags, ioStreams genericclioptions.IOStreams, cmd *cobra.Command, options *resource.FilenameOptions) error {
func RunEditOnCreate(f cmdutil.Factory, printFlags *genericclioptions.PrintFlags, recordFlags *genericclioptions.RecordFlags, ioStreams genericclioptions.IOStreams, cmd *cobra.Command, options *resource.FilenameOptions) error {
editOptions := editor.NewEditOptions(editor.EditBeforeCreateMode, ioStreams)
editOptions.FilenameOptions = *options
editOptions.ValidateOptions = cmdutil.ValidateOptions{
EnableValidation: cmdutil.GetFlagBool(cmd, "validate"),
}
editOptions.Output = cmdutil.GetFlagString(cmd, "output")
editOptions.PrintFlags = printFlags
editOptions.ApplyAnnotation = cmdutil.GetFlagBool(cmd, cmdutil.ApplyAnnotationsFlag)
editOptions.RecordFlags = recordFlags

View File

@ -60,7 +60,6 @@ type EditOptions struct {
PrintFlags *genericclioptions.PrintFlags
ToPrinter func(string) (printers.ResourcePrinter, error)
Output string
OutputPatch bool
WindowsLineEndings bool
@ -95,7 +94,6 @@ func NewEditOptions(editMode EditMode, ioStreams genericclioptions.IOStreams) *E
Recorder: genericclioptions.NoopRecorder{},
IOStreams: ioStreams,
Output: "yaml",
}
}
@ -118,12 +116,12 @@ func (o *EditOptions) Complete(f cmdutil.Factory, args []string, cmd *cobra.Comm
if o.EditMode != NormalEditMode && o.EditMode != EditBeforeCreateMode && o.EditMode != ApplyEditMode {
return fmt.Errorf("unsupported edit mode %q", o.EditMode)
}
if o.Output != "" {
if o.Output != "yaml" && o.Output != "json" {
return fmt.Errorf("invalid output format %s, only yaml|json supported", o.Output)
if *o.PrintFlags.OutputFormat != "" {
if *o.PrintFlags.OutputFormat != "yaml" && *o.PrintFlags.OutputFormat != "json" {
return fmt.Errorf("invalid output format %s, only yaml|json supported", *o.PrintFlags.OutputFormat)
}
}
o.editPrinterOptions = getPrinter(o.Output)
o.editPrinterOptions = getPrinter(*o.PrintFlags.OutputFormat)
if o.OutputPatch && o.EditMode != NormalEditMode {
return fmt.Errorf("the edit mode doesn't support output the patch")