mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-04 10:47:25 +00:00
add OutputsRawFormat helper; default show-all on multiple resource kinds
This commit is contained in:
@@ -182,13 +182,14 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
|
|||||||
return cmdutil.UsageError(cmd, usageString)
|
return cmdutil.UsageError(cmd, usageString)
|
||||||
}
|
}
|
||||||
|
|
||||||
// always show resources when getting by name or filename
|
|
||||||
argsHasNames, err := resource.HasNames(args)
|
argsHasNames, err := resource.HasNames(args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
if !cmd.Flag("show-all").Changed {
|
||||||
cmd.Flag("show-all").Value.Set("true")
|
cmd.Flag("show-all").Value.Set("true")
|
||||||
}
|
}
|
||||||
|
@@ -729,3 +729,19 @@ func RequireNoArguments(c *cobra.Command, args []string) {
|
|||||||
CheckErr(UsageError(c, fmt.Sprintf(`unknown command %q`, strings.Join(args, " "))))
|
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
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user