Skip to content

Commit

Permalink
Merge pull request #702 from pjsharath28/fix/display-proper-response-…
Browse files Browse the repository at this point in the history
…for-no-records

Updated proper response for no records while executing purge command
  • Loading branch information
Power Cloud Robot authored Dec 1, 2024
2 parents 7e2db79 + b4f7012 commit 6662d69
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
5 changes: 5 additions & 0 deletions cmd/purge/vms/vms.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ pvsadm purge --help for information
return err
}

if len(instances) == 0 {
klog.Info("No data found to display")
return nil
}

t := utils.NewTable()
t.SetHeader([]string{"Name", "IP Addresses", "Image", "CPUS", "RAM", "STATUS", "Creation Date"})
for _, instance := range instances {
Expand Down
11 changes: 9 additions & 2 deletions cmd/purge/volumes/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ package volumes

import (
"fmt"

"github.com/spf13/cobra"
"k8s.io/klog/v2"

"github.com/ppc64le-cloud/pvsadm/pkg"
"github.com/ppc64le-cloud/pvsadm/pkg/audit"
"github.com/ppc64le-cloud/pvsadm/pkg/client"
"github.com/ppc64le-cloud/pvsadm/pkg/utils"
"github.com/spf13/cobra"
"k8s.io/klog/v2"
)

var Cmd = &cobra.Command{
Expand All @@ -48,6 +50,11 @@ pvsadm purge --help for information
return fmt.Errorf("failed to get the list of volumes: %v", err)
}

if len(volumes) == 0 {
klog.Info("No data found to display")
return nil
}

t := utils.NewTable()
t.SetHeader([]string{"Name", "Volume ID", "State", "Last Update Date"})
for _, volume := range volumes {
Expand Down
11 changes: 6 additions & 5 deletions pkg/utils/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ package utils

import (
"fmt"
"github.com/go-openapi/strfmt"
"github.com/olekukonko/tablewriter"
"os"
"reflect"
"strconv"
"strings"
"sync"

"github.com/go-openapi/strfmt"
"github.com/olekukonko/tablewriter"
"k8s.io/klog/v2"
)

type Table struct {
Expand All @@ -49,9 +51,8 @@ func (t *Table) Render(rows interface{}, exclude []string) {
s := reflect.ValueOf(rows)
for i := 0; i < s.Len(); i++ {
noData = false
var headers []string
var headers, row []string
val := s.Index(i).Elem()
var row []string
for i := 0; i < val.NumField(); i++ {
if f := strings.ToLower(val.Type().Field(i).Name); Contains(exclude, f) {
continue
Expand All @@ -65,7 +66,7 @@ func (t *Table) Render(rows interface{}, exclude []string) {
}
}
if noData {
fmt.Println("\n--NO DATA FOUND--")
klog.Info("No data found to display")
}
t.Table.Render()
}
Expand Down

0 comments on commit 6662d69

Please sign in to comment.