Skip to content

Commit

Permalink
more refactor based on PR comments (1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kavinraja-G committed Jul 10, 2024
1 parent 9324910 commit 029344f
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions cmd/kueuectl/app/list/list_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,17 @@ func NewPodCmd(clientGetter util.ClientGetter, streams genericiooptions.IOStream
o := NewPodOptions(streams)

cmd := &cobra.Command{
Use: "pods --for [<type>[.<api-group>]/]<name>",
Use: "pods --for TYPE[.API-GROUP]/NAME",
DisableFlagsInUseLine: true,
Aliases: []string{"po"},
Short: "List Pods belong to a Job Kind",
Long: podLong,
Example: podExample,
Run: func(cmd *cobra.Command, args []string) {
cobra.CheckErr(o.Complete(clientGetter))
cobra.CheckErr(o.Run(cmd.Context()))
if o.ForObject != nil {
cobra.CheckErr(o.Run(cmd.Context()))
}
},
}

Expand Down Expand Up @@ -157,7 +159,7 @@ func (o *PodOptions) Complete(clientGetter util.ClientGetter) error {
return err
}
if !found {
return fmt.Errorf("invalid value '%s' used in --for flag; value must be in the format [TYPE[.API-GROUP]/]NAME", o.UserSpecifiedForObject)
return fmt.Errorf("invalid value '%s' used in --for flag; value must be in the format TYPE[.API-GROUP]/NAME", o.UserSpecifiedForObject)
}

infos, err := o.fetchDynamicResourceInfos(clientGetter)
Expand All @@ -166,11 +168,7 @@ func (o *PodOptions) Complete(clientGetter util.ClientGetter) error {
}

if len(infos) == 0 {
if !o.AllNamespaces {
fmt.Fprintf(o.ErrOut, "No resources found in %s namespace.\n", o.Namespace)
} else {
fmt.Fprintln(o.ErrOut, "No resources found")
}
o.printNoResourcesFound()
return nil
}

Expand Down Expand Up @@ -287,11 +285,7 @@ func (o *PodOptions) Run(ctx context.Context) error {

// handle if no filtered podList found
if totalCount == 0 {
if !o.AllNamespaces {
fmt.Fprintf(o.ErrOut, "No resources found in %s namespace.\n", o.Namespace)
} else {
fmt.Fprintln(o.ErrOut, "No resources found.")
}
o.printNoResourcesFound()
return nil
}

Expand Down Expand Up @@ -326,3 +320,11 @@ func (o *PodOptions) getPodLabelSelector() (string, error) {

return jobController.PodLabelSelector(), nil
}

func (o *PodOptions) printNoResourcesFound() {
if !o.AllNamespaces {
fmt.Fprintf(o.ErrOut, "No resources found in %s namespace.\n", o.Namespace)
} else {
fmt.Fprintln(o.ErrOut, "No resources found.")
}
}

0 comments on commit 029344f

Please sign in to comment.