mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 20:42:26 +00:00
return warning on empty list result in kubectl get
The current default behavior of `kubectl get` is to return an empty output when there are no resources to display. This patch improves usability by returning a warning through stderr in the case of an empty list.
This commit is contained in:
parent
b95fa62fe1
commit
7a5ed25c61
@ -124,7 +124,7 @@ func NewCmdGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Comma
|
||||
|
||||
// RunGet implements the generic Get command
|
||||
// TODO: convert all direct flag accessors to a struct and pass that instead of cmd
|
||||
func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Command, args []string, options *GetOptions) error {
|
||||
func RunGet(f *cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args []string, options *GetOptions) error {
|
||||
if len(options.Raw) > 0 {
|
||||
restClient, err := f.RESTClient()
|
||||
if err != nil {
|
||||
@ -310,6 +310,9 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm
|
||||
}
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
if len(infos) == 0 {
|
||||
outputEmptyListWarning(errOut)
|
||||
}
|
||||
|
||||
// the outermost object will be converted to the output-version, but inner
|
||||
// objects can use their mappings
|
||||
@ -365,6 +368,9 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm
|
||||
if err != nil {
|
||||
allErrs = append(allErrs, err)
|
||||
}
|
||||
if len(infos) == 0 {
|
||||
outputEmptyListWarning(errOut)
|
||||
}
|
||||
|
||||
objs := make([]runtime.Object, len(infos))
|
||||
for ix := range infos {
|
||||
@ -478,3 +484,9 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm
|
||||
}
|
||||
return utilerrors.NewAggregate(allErrs)
|
||||
}
|
||||
|
||||
// outputEmptyListWarning outputs a warning indicating that no items are available to display
|
||||
func outputEmptyListWarning(out io.Writer) error {
|
||||
_, err := fmt.Fprintf(out, "%s\n", "No resources found.")
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user