add OutputsRawFormat helper; default show-all on multiple resource kinds

This commit is contained in:
juanvallejo
2017-01-16 13:58:55 -05:00
parent cade00e646
commit 430283b973
2 changed files with 20 additions and 3 deletions

View File

@@ -182,13 +182,14 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
return cmdutil.UsageError(cmd, usageString)
}
// always show resources when getting by name or filename
argsHasNames, err := resource.HasNames(args)
if err != nil {
return err
}
output := cmdutil.GetFlagString(cmd, "output")
if len(options.Filenames) > 0 || argsHasNames || output == "json" || output == "yaml" {
// always show resources when getting by name or filename, or if the output
// is machine-consumable, or if multiple resource kinds were requested.
if len(options.Filenames) > 0 || argsHasNames || cmdutil.OutputsRawFormat(cmd) || resource.MultipleTypesRequested(args) {
if !cmd.Flag("show-all").Changed {
cmd.Flag("show-all").Value.Set("true")
}

View File

@@ -729,3 +729,19 @@ func RequireNoArguments(c *cobra.Command, args []string) {
CheckErr(UsageError(c, fmt.Sprintf(`unknown command %q`, strings.Join(args, " "))))
}
}
// OutputsRawFormat determines if a command's output format is machine parsable
// or returns false if it is human readable (name, wide, etc.)
func OutputsRawFormat(cmd *cobra.Command) bool {
output := GetFlagString(cmd, "output")
if output == "json" ||
output == "yaml" ||
output == "go-template" ||
output == "go-template-file" ||
output == "jsonpath" ||
output == "jsonpath-file" {
return true
}
return false
}