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:
juanvallejo
2016-12-08 15:26:37 -05:00
parent 00e5777b66
commit cbe479039b
3 changed files with 33 additions and 3 deletions

View File

@@ -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)
}