Skip to content

Commit 64678b6

Browse files
committed
Merge with master
2 parents 1a35ede + cd33614 commit 64678b6

47 files changed

Lines changed: 3108 additions & 416 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

QuickSetup.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
Setting up golang env
2+
3+
0: Make sure you have your SSH keys setup on github.ibm.com https://github.ibm.com/settings/keys
4+
5+
1: Know your GOPATH: https://go.dev/doc/gopath_code#GOPATH
6+
7+
```
8+
$> echo $GOPATH
9+
C:\Users\allmi\go
10+
$> cd ~/go/
11+
```
12+
13+
2: Get the softlayer-cli code https://github.ibm.com/softlayer/softlayer-cli
14+
Read the README as well.
15+
16+
```
17+
$> mkdir -p src/github.ibm.com/softlayer
18+
$> cd src/github.ibm.com/softlayer
19+
$> pwd
20+
/c/Users/allmi/go/src/github.ibm.com/softlayer
21+
$> git clone https://github.ibm.com/softlayer/softlayer-cli
22+
```
23+
24+
At this point you have the code, but need to setup the required libraries
25+
26+
3: run go mod vendor https://go.dev/ref/mod#go-mod-vendor This command will download everything listed in `go.mod`, which are the libraries this codebase uses.
27+
28+
```
29+
$> go mod vendor
30+
go: downloading github.com/IBM-Cloud/ibm-cloud-cli-sdk v1.0.1
31+
go: downloading github.com/softlayer/softlayer-go v1.1.2
32+
go: downloading github.com/miekg/dns v1.1.50
33+
go: downloading github.com/onsi/ginkgo v1.16.2
34+
go: downloading github.com/onsi/gomega v1.11.0
35+
go: downloading github.com/spf13/cobra v1.5.0
36+
go: downloading github.com/spf13/pflag v1.0.5
37+
go: downloading github.com/Xuanwo/go-locale v1.1.0
38+
go: downloading github.com/nicksnyder/go-i18n v1.10.1
39+
go: downloading golang.org/x/text v0.7.0
40+
go: downloading github.com/stretchr/testify v1.7.0
41+
go: downloading golang.org/x/net v0.7.0
42+
go: downloading golang.org/x/sys v0.5.0
43+
go: downloading golang.org/x/tools v0.1.12
44+
go: downloading github.com/fatih/color v1.10.0
45+
go: downloading github.com/mattn/go-colorable v0.1.8
46+
go: downloading github.com/mattn/go-runewidth v0.0.12
47+
go: downloading golang.org/x/crypto v0.6.0
48+
go: downloading github.com/fatih/structs v1.1.0
49+
go: downloading github.com/softlayer/xmlrpc v0.0.0-20200409220501-5f089df7cb7e
50+
go: downloading github.com/inconshreveable/mousetrap v1.0.0
51+
go: downloading github.com/davecgh/go-spew v1.1.1
52+
go: downloading github.com/pmezard/go-difflib v1.0.0
53+
go: downloading gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
54+
go: downloading gopkg.in/yaml.v2 v2.4.0
55+
go: downloading github.com/nicksnyder/go-i18n/v2 v2.2.0
56+
go: downloading github.com/mattn/go-isatty v0.0.12
57+
go: downloading github.com/rivo/uniseg v0.1.0
58+
go: downloading github.com/nxadm/tail v1.4.8
59+
go: downloading github.com/pelletier/go-toml v1.2.0
60+
go: downloading golang.org/x/term v0.5.0
61+
go: downloading gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7
62+
go: downloading github.com/fsnotify/fsnotify v1.4.9
63+
go: downloading golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4
64+
```
65+
66+
4: You can now build the softlayer-cli: https://go.dev/ref/mod#build-commands
67+
68+
```
69+
$> go build
70+
$> ./softlayer-cli.exe --help
71+
Manage Classic infrastructure services
72+
73+
Usage:
74+
sl [command]
75+
```
76+
77+
At this point you can test the softlayer-cli plugin independent of the `ibmcloud` command. If you want to test it all together, you need to ALSO build the `ibmcloud` binary.
78+
79+
5: Get the ibmcloud code https://github.ibm.com/ibmcloud-cli/bluemix-cli
80+
81+
```
82+
$> mkdir -p $GOPATH/src/github.ibm.com/ibmcloud-cli
83+
$> cd $GOPATH/src/github.ibm.com/ibmcloud-cli
84+
$> git@github.ibm.com:ibmcloud-cli/bluemix-cli.git
85+
```
86+
87+
6: Edit the ibmcloud-cli/go.mod file to force it to use the copy of softlayer-cli on your computer
88+
Add `github.ibm.com/SoftLayer/softlayer-cli => ../../SoftLayer/softlayer-cli` to the `replace` section in `github.ibm.com/ibmcloud-cli/bluemix-cli/go.mod`
89+
90+
```
91+
module github.ibm.com/ibmcloud-cli/bluemix-cli
92+
93+
go 1.20
94+
95+
replace (
96+
github.com/dgrijalva/jwt-go => github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1
97+
github.com/docker/docker => github.com/docker/engine v17.12.0-ce-rc1.0.20191121165722-d1d5f6476656+incompatible
98+
github.com/ulikunitz/xz => github.com/ulikunitz/xz v0.5.8
99+
github.ibm.com/SoftLayer/softlayer-cli => ../../SoftLayer/softlayer-cli
100+
)
101+
```
102+
103+
7: vendor and build
104+
105+
You'll need to change some git settings first to access private repositories. See https://github.ibm.com/softlayer/softlayer-cli#vendor
106+
107+
```
108+
# I usually add these to ~/.bashrc so they are always set
109+
$> export GOPROXY=direct
110+
$> export GOPRIVATE=github.ibm.com/*
111+
# Make sure you gitconfig has these lines
112+
$> git config --global url."ssh://git@github.ibm.com/".insteadof https://github.ibm.com/
113+
$> go mod vendor
114+
```
115+
116+
Need to run `go mod tidy` when you make changes to go.mod
117+
```
118+
$> go mod tidy
119+
go: downloading gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
120+
go: downloading github.com/onsi/ginkgo/v2 v2.1.6
121+
go: downloading github.com/jarcoal/httpmock v1.0.5
122+
go: downloading github.com/smartystreets/goconvey v1.6.7
123+
go: downloading github.com/BurntSushi/toml v1.1.0
124+
go: downloading golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
125+
go: downloading github.com/elazarl/goproxy v0.0.0-20210110162100-a92cc753f88e
126+
go: downloading sigs.k8s.io/yaml v1.2.0
127+
go: downloading github.com/jtolds/gls v4.20.0+incompatible
128+
go: downloading github.com/smartystreets/assertions v1.0.0
129+
go: downloading github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1
130+
go: downloading github.com/kr/pretty v0.3.0
131+
go: downloading github.com/kr/text v0.2.0
132+
go: downloading github.com/rogpeppe/go-internal v1.6.1
133+
$> go mod vendor
134+
go: downloading github.ibm.com/arf/cli-dev-plugin v1.3.4-0.20230220210426-acb097801062
135+
go: downloading github.ibm.com/SoftLayer/softlayer-cli v1.4.1
136+
go: downloading github.ibm.com/Bluemix/resource-catalog-cli v0.0.0-20220906182229-845aab607438
137+
go: downloading github.com/pelletier/go-toml v1.9.5
138+
go: downloading github.com/parnurzeal/gorequest v0.2.16
139+
go: downloading github.com/briandowns/spinner v0.0.0-20190311160019-998b3556fb3f
140+
go: downloading k8s.io/api v0.25.3
141+
go: downloading moul.io/http2curl v1.0.0
142+
go: downloading github.com/miekg/dns v1.1.25
143+
go: downloading k8s.io/apimachinery v0.25.3
144+
go: downloading github.com/gogo/protobuf v1.3.2
145+
go: downloading k8s.io/klog/v2 v2.80.0
146+
go: downloading k8s.io/utils v0.0.0-20220823124924-e9cbc92d1a73
147+
go: downloading github.com/google/gofuzz v1.2.0
148+
go: downloading gopkg.in/inf.v0 v0.9.1
149+
go: downloading sigs.k8s.io/structured-merge-diff/v4 v4.2.3
150+
go: downloading sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2
151+
go: downloading github.com/go-logr/logr v1.2.3
152+
go: downloading github.com/json-iterator/go v1.1.12
153+
go: downloading github.com/modern-go/reflect2 v1.0.2
154+
go: downloading github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
155+
156+
$> go build
157+
$> ./bluemix-cli
158+
```
159+
160+
8: Login to use it. I like to use an API key. Use https://cloud.ibm.com/iam/apikeys to create a "My IBM Cloud API Keys". It will be 32 characters long, and different from a classic infrastructure api key.
161+
162+
163+
```
164+
$> ibmcloud.exe login --apikey <keyhere>
165+
$> ibmcloud sl vs list (or some other command)
166+
```
167+
168+
169+
170+
### Uploading binaries for testing
171+
172+
Sometimes I'll upload binaries build with local softlayer-cli changes, mostly for the translation team to test with. That process is as follows:
173+
174+
175+
URL: https://s3.us-east.cloud-object-storage.appdomain.cloud/softlayer-cli-binaries/index.html
176+
CLI Docs: https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-cli-plugin-ic-cos-cli
177+
178+
COS Plugin install and setup
179+
```
180+
$> ibmcloud plugin install cloud-object-storage
181+
$> ibmcloud cos config region us-east
182+
$> ibmcloud cos config crn --crn 0859c995-bf8b-46fe-9d8b-0f3405e25359
183+
# be in the bluemix-cli directory, make sure you have the replace directive in go.mod and its ready to be build
184+
$> cd $GOPATH/src/github.ibm.com/ibmcloud-cli/bluemix-cli
185+
$> ./bin/build-all
186+
$> for i in `\ls out/`; do echo UPLOADING $i; ibmcloud.exe cos object-put --bucket=softlayer-cli-binaries --key=$i --body=./out/$i; done
187+
```
188+
Hopefully that will work.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.ibm.com/SoftLayer/softlayer-cli
33
go 1.19
44

55
require (
6-
github.com/IBM-Cloud/ibm-cloud-cli-sdk v1.0.1
6+
github.com/IBM-Cloud/ibm-cloud-cli-sdk v1.1.0
77
github.com/Xuanwo/go-locale v1.1.0
88
github.com/miekg/dns v1.1.50
99
github.com/nicksnyder/go-i18n v1.10.1
@@ -21,6 +21,7 @@ require (
2121
github.com/fatih/color v1.10.0 // indirect
2222
github.com/fatih/structs v1.1.0 // indirect
2323
github.com/fsnotify/fsnotify v1.4.9 // indirect
24+
github.com/gofrs/flock v0.8.1 // indirect
2425
github.com/inconshreveable/mousetrap v1.0.0 // indirect
2526
github.com/mattn/go-colorable v0.1.8 // indirect
2627
github.com/mattn/go-isatty v0.0.12 // indirect
@@ -34,7 +35,6 @@ require (
3435
golang.org/x/crypto v0.6.0 // indirect
3536
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
3637
golang.org/x/net v0.7.0 // indirect
37-
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
3838
golang.org/x/sys v0.5.0 // indirect
3939
golang.org/x/term v0.5.0 // indirect
4040
golang.org/x/tools v0.1.12 // indirect

go.sum

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
22
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
3-
github.com/IBM-Cloud/ibm-cloud-cli-sdk v1.0.1 h1:BucnUplOtQiTDdDdDlT0xGDYRQhvparirYuIeYZMtcE=
4-
github.com/IBM-Cloud/ibm-cloud-cli-sdk v1.0.1/go.mod h1:hBPPQhXA5hmloPcmBpow++a2NSD3tDrRYC/MN4mLbjg=
3+
github.com/IBM-Cloud/ibm-cloud-cli-sdk v1.1.0 h1:m2VQ7wYE8k3ZuV0iIuye5QIK/t6QLZa4BqOx+CteBTo=
4+
github.com/IBM-Cloud/ibm-cloud-cli-sdk v1.1.0/go.mod h1:/xwZEX9hm7/YFFEEiFa0Bes2YP5OWmXvgf9D/0o9jic=
55
github.com/Xuanwo/go-locale v1.1.0 h1:51gUxhxl66oXAjI9uPGb2O0qwPECpriKQb2hl35mQkg=
66
github.com/Xuanwo/go-locale v1.1.0/go.mod h1:UKrHoZB3FPIk9wIG2/tVSobnHgNnceGSH3Y8DY5cASs=
77
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
@@ -16,6 +16,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
1616
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
1717
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
1818
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
19+
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
20+
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
1921
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
2022
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
2123
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
@@ -42,8 +44,6 @@ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHX
4244
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
4345
github.com/mattn/go-runewidth v0.0.12 h1:Y41i/hVW3Pgwr8gV+J23B9YEY0zxjptBuCWEaxmAOow=
4446
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
45-
github.com/miekg/dns v1.1.25 h1:dFwPR6SfLtrSwgDcIq2bcU/gVutB4sNApq2HBdqcakg=
46-
github.com/miekg/dns v1.1.25/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
4747
github.com/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA=
4848
github.com/miekg/dns v1.1.50/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME=
4949
github.com/nicksnyder/go-i18n v1.10.1 h1:isfg77E/aCD7+0lD/D00ebR2MV5vgeQ276WYyDaCRQc=
@@ -87,7 +87,6 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
8787
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
8888
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
8989
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
90-
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
9190
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
9291
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
9392
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
@@ -100,7 +99,6 @@ golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73r
10099
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
101100
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
102101
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
103-
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
104102
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
105103
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
106104
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
@@ -113,13 +111,10 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
113111
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
114112
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
115113
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
116-
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
117114
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
118115
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
119116
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
120117
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
121-
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
122-
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
123118
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
124119
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
125120
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -139,15 +134,13 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn
139134
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
140135
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
141136
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
142-
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
143137
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
144138
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
145139
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
146140
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
147141
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
148142
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
149143
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
150-
golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
151144
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
152145
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
153146
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=

plugin/commands/account/billing-items.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66

77
"github.com/softlayer/softlayer-go/datatypes"
8+
"github.com/softlayer/softlayer-go/filter"
89

910
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/terminal"
1011
"github.com/spf13/cobra"
@@ -20,6 +21,9 @@ type BillingItemsCommand struct {
2021
*metadata.SoftlayerCommand
2122
AccountManager managers.AccountManager
2223
Command *cobra.Command
24+
Category string
25+
Create string
26+
Ordered string
2327
}
2428

2529
func NewBillingItemsCommand(sl *metadata.SoftlayerCommand) *BillingItemsCommand {
@@ -35,6 +39,9 @@ func NewBillingItemsCommand(sl *metadata.SoftlayerCommand) *BillingItemsCommand
3539
return thisCmd.Run(args)
3640
},
3741
}
42+
cobraCmd.Flags().StringVar(&thisCmd.Category, "category", "", T("Category name."))
43+
cobraCmd.Flags().StringVar(&thisCmd.Create, "create", "", T("The date the billing item was created (YYYY-MM-DD)."))
44+
cobraCmd.Flags().StringVar(&thisCmd.Ordered, "ordered", "", T("Name that ordered the item."))
3845
thisCmd.Command = cobraCmd
3946
return thisCmd
4047
}
@@ -43,16 +50,27 @@ func (cmd *BillingItemsCommand) Run(args []string) error {
4350

4451
outputFormat := cmd.GetOutputFlag()
4552

46-
mask := "mask[orderItem[id,order[id,userRecord[id,email,displayName,userStatus]]],nextInvoiceTotalRecurringAmount,location, hourlyFlag]"
47-
billingItems, err := cmd.AccountManager.GetBillingItems(mask)
53+
objectMask := "mask[orderItem[id,order[id,userRecord[id,email,displayName,userStatus]]],nextInvoiceTotalRecurringAmount,location, hourlyFlag]"
54+
55+
objectFilter := filter.New()
56+
objectFilter = append(objectFilter, filter.Path("allTopLevelBillingItems.id").OrderBy("ASC"))
57+
objectFilter = append(objectFilter, filter.Path("allTopLevelBillingItems.cancellationDate").IsNull())
58+
if cmd.Category != "" {
59+
objectFilter = append(objectFilter, filter.Path("allTopLevelBillingItems.categoryCode").Eq(cmd.Category))
60+
}
61+
if cmd.Create != "" {
62+
objectFilter = append(objectFilter, filter.Path("allTopLevelBillingItems.createDate").Contains(cmd.Create))
63+
}
64+
65+
billingItems, err := cmd.AccountManager.GetBillingItems(objectMask, objectFilter.Build())
4866
if err != nil {
4967
return errors.NewAPIError(T("Failed to get billing items."), err.Error(), 2)
5068
}
51-
PrintBillingItems(billingItems, cmd.UI, outputFormat)
69+
PrintBillingItems(billingItems, cmd.UI, cmd.Ordered, outputFormat)
5270
return nil
5371
}
5472

55-
func PrintBillingItems(billingItems []datatypes.Billing_Item, ui terminal.UI, outputFormat string) {
73+
func PrintBillingItems(billingItems []datatypes.Billing_Item, ui terminal.UI, orderedFilter string, outputFormat string) {
5674
bufEvent := new(bytes.Buffer)
5775
table := terminal.NewTable(bufEvent, []string{
5876
T("Id"),
@@ -74,6 +92,11 @@ func PrintBillingItems(billingItems []datatypes.Billing_Item, ui terminal.UI, ou
7492
if billingItems.OrderItem != nil {
7593
OrderedBy = utils.FormatStringPointer(billingItems.OrderItem.Order.UserRecord.DisplayName)
7694
}
95+
96+
if orderedFilter != "" && orderedFilter != OrderedBy {
97+
continue
98+
}
99+
77100
table.Add(
78101
utils.FormatIntPointer(billingItems.Id),
79102
utils.FormatSLTimePointer(billingItems.CreateDate),

0 commit comments

Comments
 (0)