Skip to content

Commit 3506136

Browse files
authored
Merge pull request IBM-Cloud#337 from IBM-Cloud/dev
Promote 1.0.0
2 parents 7d34e51 + 563bec6 commit 3506136

30 files changed

+692
-415
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
#
66
# This line indicates we will use the hook from ibm/detect-secrets to run scan during committing phase.
77
# Whitewater/whitewater-detect-secrets would sync code to ibm/detect-secrets upon merge.
8+
repos:
89
- repo: https://github.com/ibm/detect-secrets
910
# If you desire to use a specific version of detect-secrets, you can replace `master` with other git revisions such as branch, tag or commit sha.
1011
# You are encouraged to use static refs such as tags, instead of branch name
1112
#
1213
# Running "pre-commit autoupdate" would automatically updates rev to latest tag
13-
rev: master
14+
rev: 0.13.1+ibm.50.dss
1415
hooks:
1516
- id: detect-secrets # pragma: whitelist secret
1617
# Add options for detect-secrets-hook binary. You can run `detect-secrets-hook --help` to list out all possible options.
1718
# You may also run `pre-commit run detect-secrets` to preview the scan result.
1819
# when "--baseline" without "--use-all-plugins", pre-commit scan with just plugins in baseline file
1920
# when "--baseline" with "--use-all-plugins", pre-commit scan with all available plugins
20-
# add "--fail-on-non-audited" to fail pre-commit for unaudited potential secrets
21-
args: [--baseline, .secrets.baseline, --use-all-plugins, --fail-on-non-audited]
21+
# add "--fail-on-unaudited" to fail pre-commit for unaudited potential secrets
22+
args: [--baseline, .secrets.baseline, --use-all-plugins, --fail-on-unaudited]

.secrets.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@
356356
}
357357
]
358358
},
359-
"version": "0.13.1+ibm.46.dss",
359+
"version": "0.13.1+ibm.50.dss",
360360
"word_list": {
361361
"file": null,
362362
"hash": null

bin/generate-language-resources

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
set -e
44

55
go get github.com/jteeuwen/go-bindata/...
6-
go-bindata -nometadata -nocompress -pkg resources -o resources/i18n_resources.go i18n/resources/*.all.json
6+
go-bindata -nometadata -nocompress -pkg resources -o resources/i18n_resources.go i18n/resources/*.json
77

8-
pushd resources
8+
# quiet noisy pushd/popd output
9+
pushd resources 1>/dev/null
910
go fmt ./...
10-
popd
11+
popd 1>/dev/null

bluemix/terminal/table.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import (
88
"github.com/mattn/go-runewidth"
99
)
1010

11+
const (
12+
// minSpace is the number of spaces between the end of the longest value and
13+
// the start of the next row
14+
minSpace = 3
15+
)
16+
1117
type Table interface {
1218
Add(row ...string)
1319
Print()
@@ -108,10 +114,10 @@ func (t *PrintableTable) printRow(row []string) {
108114

109115
func (t *PrintableTable) cellValue(col int, value string) string {
110116
padding := ""
111-
if col < len(t.headers)-1 {
112-
padding = strings.Repeat(" ", t.maxSizes[col]-runewidth.StringWidth(Decolorize(value)))
117+
if col < len(t.maxSizes)-1 {
118+
padding = strings.Repeat(" ", t.maxSizes[col]-runewidth.StringWidth(Decolorize(value))+minSpace)
113119
}
114-
return fmt.Sprintf("%s%s ", value, padding)
120+
return fmt.Sprintf("%s%s", value, padding)
115121
}
116122

117123
// Prints out a nicely/human formatted Json string instead of a table structure

bluemix/terminal/table_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package terminal_test
22

33
import (
44
"bytes"
5-
"github.com/stretchr/testify/assert"
65
"testing"
76

7+
"github.com/stretchr/testify/assert"
8+
89
. "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/terminal"
910
)
1011

@@ -16,7 +17,7 @@ func TestPrintTableSimple(t *testing.T) {
1617
testTable.Print()
1718
assert.Contains(t, buf.String(), "test2")
1819
assert.Contains(t, buf.String(), "row1")
19-
assert.Equal(t, buf.String(), "test1 test2 \nrow1 row2 \n")
20+
assert.Equal(t, "test1 test2\nrow1 row2\n", buf.String())
2021
}
2122

2223
func TestPrintTableJson(t *testing.T) {
@@ -36,7 +37,7 @@ func TestEmptyHeaderTable(t *testing.T) {
3637
testTable.Add("row1", "row2")
3738
testTable.Print()
3839
assert.Contains(t, buf.String(), "row1")
39-
assert.Equal(t, buf.String(), " \nrow1 row2 \n")
40+
assert.Equal(t, " \nrow1 row2\n", buf.String())
4041
}
4142

4243
func TestEmptyHeaderTableJson(t *testing.T) {
@@ -55,7 +56,7 @@ func TestZeroHeadersTable(t *testing.T) {
5556
testTable.Add("row1", "row2")
5657
testTable.Print()
5758
assert.Contains(t, buf.String(), "row1")
58-
assert.Equal(t, buf.String(), "\nrow1 row2 \n")
59+
assert.Equal(t, "\nrow1 row2\n", buf.String())
5960
}
6061

6162
func TestZeroHeadersTableJson(t *testing.T) {
@@ -77,7 +78,7 @@ func TestNotEnoughRowEntires(t *testing.T) {
7778
testTable.Add("", "row2")
7879
testTable.Print()
7980
assert.Contains(t, buf.String(), "row1")
80-
assert.Equal(t, buf.String(), "col1 col2 \nrow1 \n row2 \n")
81+
assert.Equal(t, "col1 col2\nrow1 \n row2\n", buf.String())
8182
}
8283

8384
func TestNotEnoughRowEntiresJson(t *testing.T) {

bluemix/version.go

Lines changed: 1 addition & 1 deletion
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: 0, Minor: 12, Build: 0}
6+
var Version = VersionType{Major: 1, Minor: 0, Build: 0}
77

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

docs/plugin_developer_guide.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,8 @@ You can find other examples in [tests](https://github.com/maxbrunsfeld/counterfe
11141114

11151115
IBM Cloud CLI tends to be used globally. Both IBM Cloud CLI and its plug-ins should support globalization. We have enabled internationalization (i18n) for CLI's base commands with the help of the third-party tool "[go-i18n](https://github.com/nicksnyder/go-i18n)". To keep user experience consistent, we recommend plug-in developers follow the CLI's way of i18n enablement.
11161116

1117+
Please install the *go-i18n* CLI for version 1.10.0. Newer versions of the CLI are no longer compatible with translations files prior to go-i18n@2.0.0. You can install the CLI using the command: `go install github.com/nicksnyder/go-i18n/goi18n@1.10.1`
1118+
11171119
Here's the workflow:
11181120

11191121
1. Add new strings or replace existing strings with `T()` function calls to load the translated strings. For example:
@@ -1149,10 +1151,10 @@ Here's the workflow:
11491151
1. Create empty files `zh-hans.all.json` and `fr-br.all.json`, and run:
11501152
2. Run:
11511153
```bash
1152-
goi18n –outputdir <directory\_of\_generated\_translation\_files> en-us.all.json zh-hans.all.json fr-br.all.json
1154+
goi18n -flat=false –outdir <directory\_of\_generated\_translation\_files> en-us.all.json zh-hans.all.json fr-br.all.json
11531155
```
11541156

1155-
The previous command will generate 2 output files for each language: `xx-yy.all.json` contains all strings for the language, and `xx-yy.untranslated.json` contains untranslated strings. After the strings are translated, they should be merged back into `xx-yy.all.json`. For more details, refer to goi18n CLI's help by 'goi18n –help'.
1157+
The previous command will generate 2 output files for each language: `xx-yy.all.json` contains all strings for the language, and `xx-yy.untranslated.json` contains untranslated strings. After the strings are translated, they should be merged back into `xx-yy.all.json`. If plugin is on the ibm-cloud-cli-sdk 1.00 or above, rename the file from `xx-yy.all.json` to `all.xx-yy.json`. For more details, refer to goi18n CLI's help by 'goi18n –help'.
11561158
11571159
3. Package translation files. IBM Cloud CLI is to be built as a stand-alone binary distribution. In order to load i18n resource files in code, we use [go-bindata](https://github.com/jteeuwen/go-bindata) to auto-generate Go source code from all i18n resource files and the compile them into the binary. You can write a script to do it automatically during build. A sample script could be like:
11581160
@@ -1174,34 +1176,49 @@ Here's the workflow:
11741176
`T()` must be initialized before use. During i18n initialization in IBM Cloud CLI, user locale is used if it's set in `~/.bluemix/config.json` (plug-in can get user locale via `PluginContext.Locale()`). Otherwise, system locale is auto discovered (see [jibber\_jabber](https://github.com/cloudfoundry/jibber_jabber)) and used. If system locale is not detected or supported, default locale `en\_US` is then used. Next, we initialize the translate function with the locale. Sample code:
11751177

11761178
```go
1177-
func initWithLocale(locale string) goi18n.TranslateFunc {
1179+
import (
1180+
"fmt"
1181+
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/i18n"
1182+
)
1183+
1184+
var T i18n.TranslateFunc = Init(core_config.NewCoreConfig(func(e error) {}), new(JibberJabberDetector))
1185+
1186+
func Init(coreConfig core_config.Repository, detector Detector) i18n.TranslateFunc {
1187+
bundle = i18n.Bundle()
1188+
userLocale := coreConfig.Locale()
1189+
if userLocale != "" {
1190+
return initWithLocale(userLocale)
1191+
}
1192+
}
1193+
1194+
func initWithLocale(locale string) i18n.TranslateFunc {
11781195
err := loadFromAsset(locale)
11791196
if err != nil {
11801197
panic(err)
11811198
}
1182-
return goi18n.MustTfunc(locale, DEFAULT_LOCALE)
1199+
return i18n.MustTfunc(locale, DEFAULT_LOCALE)
11831200
}
11841201
11851202
// load translation asset for the given locale
11861203
func loadFromAsset(locale string) (err error) {
1187-
assetName := locale + ".all.json"
1204+
assetName := fmt.Sprintf("all.%s.json", locale)
11881205
assetKey := filepath.Join(resourcePath, assetName)
11891206
bytes, err := resources.Asset(assetKey)
11901207
if err != nil {
11911208
return
11921209
}
1193-
err = goi18n.ParseTranslationFileBytes(assetName, bytes)
1210+
_, err = bundle.ParseMessageFileBytes(bytes, resourceKey)
11941211
return
11951212
}
11961213
```
11971214

11981215
## 8. Command Design
11991216

1200-
### 8.1. Honour Region/Resource Group Setting of CLI
1217+
### 8.1. Honor Region/Resource Group Setting of CLI
12011218

12021219
When users are using CLI, they probably have already targeted region or resource group during login. It's cumbersome to ask users to re-target region or resource group in specific command again.
12031220
1204-
- By default, plugin should honour the region/resource group setting of CLI. Check `CurrentRegion`, `HasTargetedRegion`, `CurrentResourceGroup`, and `HasTargetedResourceGroup` in the [`core_config.Repository`](https://godoc.org/github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/configuration/core_config#Repository).
1221+
- By default, plugin should honor the region/resource group setting of CLI. Check `CurrentRegion`, `HasTargetedRegion`, `CurrentResourceGroup`, and `HasTargetedResourceGroup` in the [`core_config.Repository`](https://godoc.org/github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/configuration/core_config#Repository).
12051222
12061223
```go
12071224
func (demo *DemoPlugin) Run(context plugin.PluginContext, args []string){

go.mod

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,31 @@ require (
77
github.com/fatih/structs v1.0.1-0.20171020064819-f5faa72e7309
88
github.com/mattn/go-colorable v0.0.0-20160210001857-9fdad7c47650
99
github.com/mattn/go-runewidth v0.0.0-20151118072159-d96d1bd051f2
10-
github.com/nicksnyder/go-i18n v1.3.0
11-
github.com/onsi/ginkgo v1.3.1
12-
github.com/onsi/gomega v1.1.0
10+
github.com/nicksnyder/go-i18n/v2 v2.2.0
11+
github.com/onsi/ginkgo v1.6.0
12+
github.com/onsi/gomega v1.10.0
1313
github.com/spf13/cobra v1.0.0
1414
github.com/spf13/pflag v1.0.3
1515
github.com/stretchr/testify v1.2.2
1616
golang.org/x/crypto v0.0.0-20211202192323-5770296d904e
17+
golang.org/x/text v0.3.7
1718
gopkg.in/cheggaaa/pb.v1 v1.0.15
1819
gopkg.in/yaml.v2 v2.4.0
1920
)
2021

2122
require (
23+
github.com/BurntSushi/toml v1.1.0 // indirect
2224
github.com/davecgh/go-spew v1.1.1 // indirect
23-
github.com/golang/protobuf v1.3.1 // indirect
25+
github.com/golang/protobuf v1.5.2 // indirect
26+
github.com/hpcloud/tail v1.0.0 // indirect
2427
github.com/inconshreveable/mousetrap v1.0.0 // indirect
2528
github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035 // indirect
2629
github.com/pmezard/go-difflib v1.0.0 // indirect
27-
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
28-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
30+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
31+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
32+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
33+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
34+
google.golang.org/protobuf v1.26.0 // indirect
35+
gopkg.in/fsnotify.v1 v1.4.7 // indirect
36+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
2937
)

0 commit comments

Comments
 (0)