Skip to content

Commit d2df65c

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #865 from SoftLayer/issues862
Changed hardware and vs bandwidth flag quite to quiet.
2 parents 63168bc + 85a3f67 commit d2df65c

5 files changed

Lines changed: 48 additions & 90 deletions

File tree

plugin/commands/hardware/bandwidth.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type BandwidthCommand struct {
2020
Start string
2121
End string
2222
Rollup int
23-
quite bool
23+
quiet bool
2424
}
2525

2626
func NewBandwidthCommand(sl *metadata.SoftlayerCommand) (cmd *BandwidthCommand) {
@@ -50,7 +50,8 @@ Example::
5050
cobraCmd.Flags().StringVarP(&thisCmd.Start, "start", "s", "", T("Start date for bandwdith reporting"))
5151
cobraCmd.Flags().StringVarP(&thisCmd.End, "end", "e", "", T("End date for bandwidth reporting"))
5252
cobraCmd.Flags().IntVarP(&thisCmd.Rollup, "rollup", "r", 0, T("Number of seconds to report as one data point. 300, 600, 1800, 3600 (default), 43200 or 86400 seconds"))
53-
cobraCmd.Flags().BoolVarP(&thisCmd.quite, "quite", "q", false, T("Only show the summary table."))
53+
cobraCmd.Flags().BoolVarP(&thisCmd.quiet, "quiet", "q", false, T("Only show the summary table."))
54+
cobraCmd.Flags().SetNormalizeFunc(utils.NormalizeQuietFlag)
5455

5556
thisCmd.Command = cobraCmd
5657
return thisCmd
@@ -98,7 +99,7 @@ func (cmd *BandwidthCommand) Run(args []string) error {
9899

99100
summaryTable, bandwidthTable := virtual.BuildOutputTable(bandwidthData, cmd.UI)
100101
summaryTable.Print()
101-
if !cmd.quite {
102+
if !cmd.quiet {
102103
bandwidthTable.Print()
103104
}
104105

plugin/commands/hardware/bandwidth_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,19 @@ var _ = Describe("Hardware bandwidth", func() {
127127
})
128128
It("Quiet output", func() {
129129
fakeHardwareManager.GetBandwidthDataReturns(returnData, nil)
130-
err := testhelpers.RunCobraCommand(cliCommand.Command, "123456", "-s", testTime, "-e", testTime, "-q")
130+
err := testhelpers.RunCobraCommand(cliCommand.Command, "123456", "-s", testTime, "-e", testTime, "--quiet")
131+
Expect(err).NotTo(HaveOccurred())
132+
outputs := fakeUI.Outputs()
133+
Expect(outputs).To(ContainSubstring("Pub In 0.0032 0.2689 0.0016 2021-07-31 23:00"))
134+
Expect(outputs).NotTo(ContainSubstring("2021-07-31 23:00 0.0016 0.0017 0.0000 0.0000"))
135+
})
136+
It("Quiet output, misspelled flag", func() {
137+
fakeHardwareManager.GetBandwidthDataReturns(returnData, nil)
138+
err := testhelpers.RunCobraCommand(cliCommand.Command, "123456", "-s", testTime, "-e", testTime, "--quite")
131139
Expect(err).NotTo(HaveOccurred())
132140
outputs := fakeUI.Outputs()
133141
Expect(outputs).To(ContainSubstring("Pub In 0.0032 0.2689 0.0016 2021-07-31 23:00"))
134142
Expect(outputs).NotTo(ContainSubstring("2021-07-31 23:00 0.0016 0.0017 0.0000 0.0000"))
135-
136143
})
137144
It("Empty Response", func() {
138145
fakeHardwareManager.GetBandwidthDataReturns([]datatypes.Metric_Tracking_Object_Data{}, nil)

plugin/commands/virtual/bandwidth.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type BandwidthCommand struct {
2323
Start string
2424
End string
2525
Rollup int
26-
Quite bool
26+
quiet bool
2727
}
2828

2929
type SummaryDataType struct {
@@ -59,7 +59,8 @@ Example::
5959
cobraCmd.Flags().StringVarP(&thisCmd.Start, "start", "s", "", T("Start date for bandwdith reporting"))
6060
cobraCmd.Flags().StringVarP(&thisCmd.End, "end", "e", "", T("End date for bandwidth reporting"))
6161
cobraCmd.Flags().IntVarP(&thisCmd.Rollup, "rollup", "r", 3600, T("Number of seconds to report as one data point. 300, 600, 1800, 3600 (default), 43200 or 86400 seconds"))
62-
cobraCmd.Flags().BoolVarP(&thisCmd.Quite, "quite", "q", false, T("Only show the summary table."))
62+
cobraCmd.Flags().BoolVarP(&thisCmd.quiet, "quiet", "q", false, T("Only show the summary table."))
63+
cobraCmd.Flags().SetNormalizeFunc(utils.NormalizeQuietFlag)
6364
return thisCmd
6465
}
6566

@@ -105,7 +106,7 @@ func (cmd *BandwidthCommand) Run(args []string) error {
105106

106107
summaryTable, bandwidthTable := BuildOutputTable(bandwidthData, cmd.UI)
107108
summaryTable.Print()
108-
if !cmd.Quite {
109+
if !cmd.quiet {
109110
bandwidthTable.Print()
110111
}
111112

plugin/utils/utils.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import (
1111
"strings"
1212
"time"
1313

14-
bmxErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
15-
1614
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/terminal"
1715
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/trace"
1816
"github.com/softlayer/softlayer-go/datatypes"
1917
"github.com/softlayer/softlayer-go/services"
2018
"github.com/softlayer/softlayer-go/session"
2119
"github.com/softlayer/softlayer-go/sl"
20+
"github.com/spf13/pflag"
21+
bmxErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
2222
. "github.ibm.com/SoftLayer/softlayer-cli/plugin/i18n"
2323
"github.ibm.com/SoftLayer/softlayer-cli/plugin/progress_bar"
2424
)
@@ -570,3 +570,15 @@ func FormatStringToTime(timestamp *string) string {
570570
return t.Format("2006-01-02 15:04:05")
571571

572572
}
573+
574+
// I always mix these up
575+
// QUIET => SHHHHHH
576+
// QUITE => absolutely; completely
577+
func NormalizeQuietFlag(f *pflag.FlagSet, name string) pflag.NormalizedName {
578+
switch name {
579+
case "quite":
580+
name = "quiet"
581+
break
582+
}
583+
return pflag.NormalizedName(name)
584+
}

plugin/utils/utils_test.go

Lines changed: 17 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package utils_test
33
import (
44
. "github.com/onsi/ginkgo/v2"
55
. "github.com/onsi/gomega"
6+
"github.com/spf13/pflag"
67
"github.ibm.com/SoftLayer/softlayer-cli/plugin/utils"
78
)
89

@@ -40,84 +41,20 @@ var _ = Describe("Utility Tests", func() {
4041
Entry("String", "NinteyNine", 0, "strconv.Atoi: parsing \"NinteyNine\": invalid syntax"),
4142
Entry("Nil", nil, 0, "strconv.Atoi: parsing \"\": invalid syntax"),
4243
)
44+
Describe("normalizeQuietFlag Tests", func() {
45+
It("Test quite => quiet", func() {
46+
flagSet := pflag.NewFlagSet("testSet", 0)
47+
var fakeBoolVar bool
48+
flagSet.BoolVarP(&fakeBoolVar, "quiet", "q", false, "test")
49+
result := utils.NormalizeQuietFlag(flagSet, "quite")
50+
Expect(string(result)).To(Equal("quiet"))
51+
})
52+
It("Test nothing else is changed", func() {
53+
flagSet := pflag.NewFlagSet("testSet", 0)
54+
var fakeBoolVar bool
55+
flagSet.BoolVarP(&fakeBoolVar, "quiet", "q", false, "test")
56+
result := utils.NormalizeQuietFlag(flagSet, "asd")
57+
Expect(string(result)).To(Equal("asd"))
58+
})
59+
})
4360
})
44-
45-
/*
46-
func TestSliceInSlice(t *testing.T) {
47-
source := []string{"id", "hostnamdde"}
48-
defaultColumns := []string{"id", "hostname", "domain", "cpu", "memory", "primary_ip", "backend_ip", "datacenter", "action"}
49-
optionalColumns := []string{"guid", "power_state", "created_by", "tags"}
50-
target := append(defaultColumns, optionalColumns...)
51-
52-
exist, idx := SliceInSlice(source, target)
53-
Equal(t, false, exist)
54-
Equal(t, 1, idx)
55-
}
56-
57-
func TestStringSliceToString(t *testing.T) {
58-
sclice := []string{"aaa", "bbb"}
59-
result := StringSliceToString(sclice)
60-
Equal(t, "aaa,bbb", result)
61-
}
62-
63-
func TestTagRefsToString(t *testing.T) {
64-
tags := []datatypes.Tag_Reference{
65-
datatypes.Tag_Reference{
66-
Tag: &datatypes.Tag{
67-
Name: sl.String("aaa"),
68-
},
69-
},
70-
datatypes.Tag_Reference{
71-
Tag: &datatypes.Tag{
72-
Name: sl.String("bbb"),
73-
},
74-
},
75-
}
76-
result := TagRefsToString(tags)
77-
Equal(t, "aaa,bbb", result)
78-
}
79-
80-
func TestBool2Int(t *testing.T) {
81-
value1 := true
82-
result1 := Bool2Int(value1)
83-
Equal(t, result1, 1)
84-
value2 := false
85-
result2 := Bool2Int(value2)
86-
Equal(t, result2, 0)
87-
}
88-
89-
func TestStructToMap(t *testing.T) {
90-
access := Access{
91-
ID: "1",
92-
Name: "2",
93-
Type: "3",
94-
PrivateIPAddress: "4",
95-
SourceSubnet: "5",
96-
HostIQN: "6",
97-
UserName: "7",
98-
Password: "8",
99-
AllowedHostID: "9",
100-
}
101-
accessMap, err := StructToMap(access)
102-
Equal(t, err, nil)
103-
Equal(t, accessMap, map[string]string{"id": "1", "name": "2", "type": "3", "private_ip_address": "4", "source_subnet": "5", "host_iqn": "6", "username": "7", "password": "8", "allowed_host_id": "9"})
104-
}
105-
106-
func TestStructToMap1(t *testing.T) {
107-
access := Access{
108-
ID: "a",
109-
Name: "b",
110-
Type: "c",
111-
PrivateIPAddress: "d",
112-
SourceSubnet: "e",
113-
HostIQN: "f",
114-
UserName: "g",
115-
Password: "h",
116-
AllowedHostID: "i",
117-
}
118-
accessMap, err := StructToMap(access)
119-
Equal(t, err, nil)
120-
Equal(t, accessMap, map[string]string{"id": "a", "name": "b", "type": "c", "private_ip_address": "d", "source_subnet": "e", "host_iqn": "f", "username": "g", "password": "h", "allowed_host_id": "i"})
121-
}
122-
123-
*/

0 commit comments

Comments
 (0)