Skip to content

Commit 14d2e08

Browse files
authoredJun 7, 2023
Merge pull request #375 from IBM-Cloud/dev
SDK Release 1.1.0
2 parents 01bf208 + d9b96d6 commit 14d2e08

19 files changed

+319
-74
lines changed
 

‎bluemix/configuration/config_helpers/helpers_test.go

+5-11
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ import (
1010
"github.com/stretchr/testify/assert"
1111
)
1212

13-
// import (
14-
// "io/ioutil"
15-
// "os"
16-
// "path/filepath"
17-
// "testing"
18-
19-
// "github.com/stretchr/testify/assert"
20-
// "github.ibm.com/bluemix-cli-release/build/src/github.ibm.com/Bluemix/bluemix-cli-common/file_helpers"
21-
// )
22-
2313
func captureAndPrepareEnv(a *assert.Assertions) ([]string, string) {
2414
env := os.Environ()
2515

@@ -30,7 +20,11 @@ func captureAndPrepareEnv(a *assert.Assertions) ([]string, string) {
3020
os.Unsetenv("IBMCLOUD_HOME")
3121
os.Unsetenv("BLUEMIX_HOME")
3222
os.Setenv("HOME", userHome)
33-
23+
// UserHomeDir() uses HOMEDRIVE + HOMEPATH for windows
24+
if os.Getenv("OS") == "Windows_NT" {
25+
// ioutil.TempDir has the drive letter in the path, so we need to remove it when we set HOMEDRIVE
26+
os.Setenv("HOMEPATH", strings.Replace(userHome, os.Getenv("HOMEDRIVE"), "", -1))
27+
}
3428
a.NoError(os.RemoveAll(userHome))
3529

3630
return env, userHome

‎bluemix/env_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
)
1010

1111
func TestGet(t *testing.T) {
12-
assert.Empty(t, EnvTrace.Get())
13-
1412
os.Setenv("IBMCLOUD_TRACE", "true")
1513
assert.Equal(t, "true", EnvTrace.Get())
1614

‎bluemix/terminal/table.go

+16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package terminal
22

33
import (
4+
"encoding/csv"
45
"fmt"
56
"io"
67
"strings"
78

9+
. "github.com/IBM-Cloud/ibm-cloud-cli-sdk/i18n"
810
"github.com/mattn/go-runewidth"
911
)
1012

@@ -18,6 +20,7 @@ type Table interface {
1820
Add(row ...string)
1921
Print()
2022
PrintJson()
23+
PrintCsv() error
2124
}
2225

2326
type PrintableTable struct {
@@ -157,3 +160,16 @@ func (t *PrintableTable) PrintJson() {
157160
// mimic behavior of Print()
158161
t.rows = [][]string{}
159162
}
163+
164+
func (t *PrintableTable) PrintCsv() error {
165+
csvwriter := csv.NewWriter(t.writer)
166+
err := csvwriter.Write(t.headers)
167+
if err != nil {
168+
return fmt.Errorf(T("Failed, header could not convert to csv format"), err.Error())
169+
}
170+
err = csvwriter.WriteAll(t.rows)
171+
if err != nil {
172+
return fmt.Errorf(T("Failed, rows could not convert to csv format"), err.Error())
173+
}
174+
return nil
175+
}

‎bluemix/terminal/table_test.go

+45
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package terminal_test
22

33
import (
44
"bytes"
5+
"strings"
56
"testing"
67

78
"github.com/stretchr/testify/assert"
@@ -92,3 +93,47 @@ func TestNotEnoughRowEntiresJson(t *testing.T) {
9293
assert.Contains(t, buf.String(), "\"column_1\": \"row1\"")
9394
assert.Contains(t, buf.String(), "\"column_1\": \"\"")
9495
}
96+
97+
func TestPrintCsvSimple(t *testing.T) {
98+
buf := bytes.Buffer{}
99+
testTable := NewTable(&buf, []string{"col1", "col2"})
100+
testTable.Add("row1-col1", "row1-col2")
101+
testTable.Add("row2-col1", "row2-col2")
102+
err := testTable.PrintCsv()
103+
assert.Equal(t, err, nil)
104+
assert.Contains(t, buf.String(), "col1,col2")
105+
assert.Contains(t, buf.String(), "row1-col1,row1-col2")
106+
assert.Contains(t, buf.String(), "row2-col1,row2-col2")
107+
}
108+
109+
func TestNotEnoughColPrintCsv(t *testing.T) {
110+
buf := bytes.Buffer{}
111+
testTable := NewTable(&buf, []string{"", "col2"})
112+
testTable.Add("row1-col1", "row1-col2")
113+
testTable.Add("row2-col1", "row2-col2")
114+
err := testTable.PrintCsv()
115+
assert.Equal(t, err, nil)
116+
assert.Contains(t, buf.String(), ",col2")
117+
assert.Contains(t, buf.String(), "row1-col1,row1-col2")
118+
assert.Contains(t, buf.String(), "row2-col1,row2-col2")
119+
}
120+
121+
func TestNotEnoughRowPrintCsv(t *testing.T) {
122+
buf := bytes.Buffer{}
123+
testTable := NewTable(&buf, []string{"col1", "col2"})
124+
testTable.Add("row1-col1", "row1-col2")
125+
testTable.Add("row2-col1", "")
126+
err := testTable.PrintCsv()
127+
assert.Equal(t, err, nil)
128+
assert.Contains(t, buf.String(), "col1,col2")
129+
assert.Contains(t, buf.String(), "row1-col1,row1-col2")
130+
assert.Contains(t, buf.String(), "row2-col1,")
131+
}
132+
133+
func TestEmptyTable(t *testing.T) {
134+
buf := bytes.Buffer{}
135+
testTable := NewTable(&buf, []string{})
136+
err := testTable.PrintCsv()
137+
assert.Equal(t, err, nil)
138+
assert.Equal(t, len(strings.TrimSpace(buf.String())), 0)
139+
}

‎bluemix/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package bluemix
33
import "fmt"
44

55
// Version is the SDK version
6-
var Version = VersionType{Major: 1, Minor: 0, Build: 3}
6+
var Version = VersionType{Major: 1, Minor: 1, Build: 0}
77

88
// VersionType describe version info
99
type VersionType struct {

‎common/rest/client.go

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func (c *Client) DoWithContext(ctx context.Context, r *Request, respV interface{
6363
client = http.DefaultClient
6464
}
6565

66+
req.Close = true
6667
resp, err := client.Do(req)
6768
if err != nil {
6869
return resp, err

‎go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.17
55
require (
66
github.com/fatih/color v1.7.1-0.20180516100307-2d684516a886
77
github.com/fatih/structs v1.0.1-0.20171020064819-f5faa72e7309
8+
github.com/gofrs/flock v0.8.1
89
github.com/mattn/go-colorable v0.0.0-20160210001857-9fdad7c47650
910
github.com/mattn/go-runewidth v0.0.0-20151118072159-d96d1bd051f2
1011
github.com/nicksnyder/go-i18n/v2 v2.2.0
@@ -22,10 +23,10 @@ require (
2223
require (
2324
github.com/BurntSushi/toml v1.1.0 // indirect
2425
github.com/davecgh/go-spew v1.1.1 // indirect
25-
github.com/gofrs/flock v0.8.1 // indirect
2626
github.com/golang/protobuf v1.5.2 // indirect
2727
github.com/hpcloud/tail v1.0.0 // indirect
2828
github.com/inconshreveable/mousetrap v1.0.0 // indirect
29+
github.com/jteeuwen/go-bindata v3.0.7+incompatible // indirect
2930
github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035 // indirect
3031
github.com/pmezard/go-difflib v1.0.0 // indirect
3132
golang.org/x/net v0.7.0 // indirect

‎go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
5858
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
5959
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
6060
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
61+
github.com/jteeuwen/go-bindata v3.0.7+incompatible h1:91Uy4d9SYVr1kyTJ15wJsog+esAZZl7JmEfTkwmhJts=
62+
github.com/jteeuwen/go-bindata v3.0.7+incompatible/go.mod h1:JVvhzYOiGBnFSYRyV00iY8q7/0PThjIYav1p9h5dmKs=
6163
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
6264
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
6365
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=

‎i18n/resources/all.de_DE.json

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
"id": "FAILED",
3232
"translation": "FEHLGESCHLAGEN"
3333
},
34+
{
35+
"id": "Failed, header could not convert to csv format",
36+
"translation": "Failed, header could not convert to csv format"
37+
},
38+
{
39+
"id": "Failed, rows could not convert to csv format",
40+
"translation": "Failed, rows could not convert to csv format"
41+
},
3442
{
3543
"id": "Invalid grant type: ",
3644
"translation": "Invalid grant type: "

‎i18n/resources/all.en_US.json

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
"id": "FAILED",
3232
"translation": "FAILED"
3333
},
34+
{
35+
"id": "Failed, header could not convert to csv format",
36+
"translation": "Failed, header could not convert to csv format"
37+
},
38+
{
39+
"id": "Failed, rows could not convert to csv format",
40+
"translation": "Failed, rows could not convert to csv format"
41+
},
3442
{
3543
"id": "Invalid grant type: ",
3644
"translation": "Invalid grant type: "

‎i18n/resources/all.es_ES.json

+8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
"id": "FAILED",
3131
"translation": "ERROR"
3232
},
33+
{
34+
"id": "Failed, header could not convert to csv format",
35+
"translation": "Failed, header could not convert to csv format"
36+
},
37+
{
38+
"id": "Failed, rows could not convert to csv format",
39+
"translation": "Failed, rows could not convert to csv format"
40+
},
3341
{
3442
"id": "Invalid grant type: ",
3543
"translation": "Invalid grant type: "

‎i18n/resources/all.fr_FR.json

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
"id": "FAILED",
3232
"translation": "ECHEC"
3333
},
34+
{
35+
"id": "Failed, header could not convert to csv format",
36+
"translation": "Failed, header could not convert to csv format"
37+
},
38+
{
39+
"id": "Failed, rows could not convert to csv format",
40+
"translation": "Failed, rows could not convert to csv format"
41+
},
3442
{
3543
"id": "Invalid grant type: ",
3644
"translation": "Invalid grant type: "

‎i18n/resources/all.it_IT.json

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
"id": "FAILED",
3232
"translation": "NON RIUSCITO"
3333
},
34+
{
35+
"id": "Failed, header could not convert to csv format",
36+
"translation": "Failed, header could not convert to csv format"
37+
},
38+
{
39+
"id": "Failed, rows could not convert to csv format",
40+
"translation": "Failed, rows could not convert to csv format"
41+
},
3442
{
3543
"id": "Invalid grant type: ",
3644
"translation": "Invalid grant type: "

‎i18n/resources/all.ja_JP.json

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
"id": "FAILED",
3232
"translation": "失敗"
3333
},
34+
{
35+
"id": "Failed, header could not convert to csv format",
36+
"translation": "Failed, header could not convert to csv format"
37+
},
38+
{
39+
"id": "Failed, rows could not convert to csv format",
40+
"translation": "Failed, rows could not convert to csv format"
41+
},
3442
{
3543
"id": "Invalid grant type: ",
3644
"translation": "Invalid grant type: "

‎i18n/resources/all.ko_KR.json

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
"id": "FAILED",
3232
"translation": "실패"
3333
},
34+
{
35+
"id": "Failed, header could not convert to csv format",
36+
"translation": "Failed, header could not convert to csv format"
37+
},
38+
{
39+
"id": "Failed, rows could not convert to csv format",
40+
"translation": "Failed, rows could not convert to csv format"
41+
},
3442
{
3543
"id": "Invalid grant type: ",
3644
"translation": "Invalid grant type: "

‎i18n/resources/all.pt_BR.json

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
"id": "FAILED",
3232
"translation": "COM FALHA"
3333
},
34+
{
35+
"id": "Failed, header could not convert to csv format",
36+
"translation": "Failed, header could not convert to csv format"
37+
},
38+
{
39+
"id": "Failed, rows could not convert to csv format",
40+
"translation": "Failed, rows could not convert to csv format"
41+
},
3442
{
3543
"id": "Invalid grant type: ",
3644
"translation": "Invalid grant type: "

‎i18n/resources/all.zh_Hans.json

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
"id": "FAILED",
3232
"translation": "失败"
3333
},
34+
{
35+
"id": "Failed, header could not convert to csv format",
36+
"translation": "Failed, header could not convert to csv format"
37+
},
38+
{
39+
"id": "Failed, rows could not convert to csv format",
40+
"translation": "Failed, rows could not convert to csv format"
41+
},
3442
{
3543
"id": "Invalid grant type: ",
3644
"translation": "Invalid grant type: "

‎i18n/resources/all.zh_Hant.json

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
"id": "FAILED",
3232
"translation": "失敗"
3333
},
34+
{
35+
"id": "Failed, header could not convert to csv format",
36+
"translation": "Failed, header could not convert to csv format"
37+
},
38+
{
39+
"id": "Failed, rows could not convert to csv format",
40+
"translation": "Failed, rows could not convert to csv format"
41+
},
3442
{
3543
"id": "Invalid grant type: ",
3644
"translation": "Invalid grant type: "

0 commit comments

Comments
 (0)
Failed to load comments.