mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-01 10:48:15 +00:00
Add json,yaml output format support kubectl create
This patch adds the ability to specify an output format other than "name" to `kubectl create ...`. It can be used in conjunction with the `--dry-run` option. Converts unstructured objects into known types in order to support all `--output` values.
This commit is contained in:
@@ -130,6 +130,7 @@ func RunCreate(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opt
|
||||
}
|
||||
|
||||
dryRun := cmdutil.GetFlagBool(cmd, "dry-run")
|
||||
output := cmdutil.GetFlagString(cmd, "output")
|
||||
|
||||
count := 0
|
||||
err = r.Visit(func(info *resource.Info, err error) error {
|
||||
@@ -153,7 +154,11 @@ func RunCreate(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opt
|
||||
}
|
||||
|
||||
count++
|
||||
shortOutput := cmdutil.GetFlagString(cmd, "output") == "name"
|
||||
|
||||
shortOutput := output == "name"
|
||||
if len(output) > 0 && !shortOutput {
|
||||
return cmdutil.PrintResourceInfoForCommand(cmd, info, f, out)
|
||||
}
|
||||
if !shortOutput {
|
||||
f.PrintObjectSpecificMessage(info.Object, out)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user