Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated proper response for no records while executing purge command #702

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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