@@ -47,7 +47,7 @@ to generate the API structure for a template to which you can add parameters and
47
47
%[1]s export service -o json`
48
48
)
49
49
50
- func NewCmdExport (fullName string , f * clientcmd.Factory , in io.Reader , out io.Writer ) * cobra.Command {
50
+ func NewCmdExport (fullName string , f * clientcmd.Factory , in io.Reader , out , errOut io.Writer ) * cobra.Command {
51
51
exporter := & DefaultExporter {}
52
52
var filenames []string
53
53
cmd := & cobra.Command {
@@ -56,7 +56,7 @@ func NewCmdExport(fullName string, f *clientcmd.Factory, in io.Reader, out io.Wr
56
56
Long : exportLong ,
57
57
Example : fmt .Sprintf (exportExample , fullName ),
58
58
Run : func (cmd * cobra.Command , args []string ) {
59
- err := RunExport (f , exporter , in , out , cmd , args , filenames )
59
+ err := RunExport (f , exporter , in , out , errOut , cmd , args , filenames )
60
60
if err == cmdutil .ErrExit {
61
61
os .Exit (1 )
62
62
}
@@ -76,7 +76,7 @@ func NewCmdExport(fullName string, f *clientcmd.Factory, in io.Reader, out io.Wr
76
76
return cmd
77
77
}
78
78
79
- func RunExport (f * clientcmd.Factory , exporter Exporter , in io.Reader , out io.Writer , cmd * cobra.Command , args []string , filenames []string ) error {
79
+ func RunExport (f * clientcmd.Factory , exporter Exporter , in io.Reader , out , errOut io.Writer , cmd * cobra.Command , args []string , filenames []string ) error {
80
80
selector := kcmdutil .GetFlagString (cmd , "selector" )
81
81
allNamespaces := kcmdutil .GetFlagBool (cmd , "all-namespaces" )
82
82
exact := kcmdutil .GetFlagBool (cmd , "exact" )
@@ -171,5 +171,18 @@ func RunExport(f *clientcmd.Factory, exporter Exporter, in io.Reader, out io.Wri
171
171
if err != nil {
172
172
return err
173
173
}
174
- return p .PrintObj (result , out )
174
+ err = p .PrintObj (result , out )
175
+ if err != nil {
176
+ return err
177
+ }
178
+
179
+ // validSpecifiedVersion resolves to true if the version passed to this function matches the
180
+ // version assigned to the converted object
181
+ validSpecifiedVersion := (result .GetObjectKind ().GroupVersionKind ().Version == outputVersion .Version )
182
+ outputVersionString := kcmdutil .GetFlagString (cmd , "output-version" )
183
+ if ! validSpecifiedVersion && len (outputVersionString ) > 0 {
184
+ err = fmt .Errorf ("the output version specified (%v) is invalid, defaulting to %v\n " , outputVersion , clientConfig .GroupVersion )
185
+ }
186
+
187
+ return err
175
188
}
0 commit comments