Skip to content

Commit

Permalink
Merge branch 'master' into vpc
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian authored Aug 6, 2021
2 parents a0f837d + e70bc4c commit abf5e81
Show file tree
Hide file tree
Showing 36 changed files with 259 additions and 144 deletions.
7 changes: 3 additions & 4 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ clone_folder: C:\Users\appveyor\go\src\github.com\aliyun\aliyun-cli
# scripts that run after cloning repository
install:
# by default, all script lines are interpreted as batch
- cmd: git clone -q --branch=master https://github.com/aliyun/aliyun-openapi-meta.git C:\Users\appveyor\go\src\github.com\aliyun\aliyun-openapi-meta
- cmd: git submodule update --init --recursive
- cmd: set path=%path%;C:\Users\appveyor\go\bin
- cmd: set VERSION=3.0.81
- cmd: set VERSION=3.0.85
- cmd: go get -u github.com/shuLhan/go-bindata/...
- cmd: go-bindata -o resource/metas.go -pkg resource -prefix ../aliyun-openapi-meta ../aliyun-openapi-meta/...
- cmd: go-bindata -o resource/metas.go -pkg resource ./aliyun-openapi-meta/...
- cmd: go build -ldflags "-X 'github.com/aliyun/aliyun-cli/cli.Version=%VERSION%'" -o C:\Users\appveyor\go\bin\aliyun.exe main/main.go

# build platform, i.e. x86, x64, Any CPU. This setting is optional.
Expand All @@ -28,4 +28,3 @@ test_script:
$client.DownloadFile('https://github.com/stedolan/jq/releases/download/jq-1.6/jq-win64.exe', 'C:/go/bin/jq.exe')
if (-not $env:ACCESS_KEY_ID.length -eq 0 -and -not $env:ACCESS_KEY_SECRET.length -eq 0){./integration/ecs_test.PS1}
4 changes: 4 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ jobs:

build:
runs-on: ubuntu-latest
env:
ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }}
ACCESS_KEY_SECRET: ${{ secrets.ACCESS_KEY_SECRET }}
REGION_ID: ${{ secrets.REGION_ID }}
steps:
- uses: actions/checkout@v2
# fetch submodule for aliyun-openapi-meta
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ before_install:
- sudo apt-get install -y jq

install:
- git submodule update --init --recursive
- make build
- sudo cp out/aliyun /usr/local/bin

Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

### Master

### 3.0.85

- update: meta data

### 3.0.84

- update: meta data

### 3.0.83

- update: meta data

### 3.0.82

- update: meta data

### 3.0.81

- update: meta data
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export VERSION=3.0.81
export VERSION=3.0.85
export RELEASE_PATH="releases/aliyun-cli-${VERSION}"

all: build
Expand Down
8 changes: 4 additions & 4 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ CLI 版本更改说明请参考 [CHANGELOG](./CHANGELOG.md)

阿里云CLI工具下载、解压后即可使用,支持Mac, Linux, Windows平台(x64版本)。您可以将解压的`aliyun`可执行文件移至`/usr/local/bin`目录下,或添加到`$PATH`中。

下载链接如下 (3.0.81):
下载链接如下 (3.0.85):

- [Mac](https://aliyuncli.alicdn.com/aliyun-cli-macosx-3.0.81-amd64.tgz)
- [Linux](https://aliyuncli.alicdn.com/aliyun-cli-linux-3.0.81-amd64.tgz)
- [Windows (64 bit)](https://aliyuncli.alicdn.com/aliyun-cli-windows-3.0.81-amd64.zip)
- [Mac](https://aliyuncli.alicdn.com/aliyun-cli-macosx-3.0.85-amd64.tgz)
- [Linux](https://aliyuncli.alicdn.com/aliyun-cli-linux-3.0.85-amd64.tgz)
- [Windows (64 bit)](https://aliyuncli.alicdn.com/aliyun-cli-windows-3.0.85-amd64.zip)

- **使用brew**

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ The release notes for the CLI can be found in the [CHANGELOG](./CHANGELOG.md)

Download the installer, then extract the installer. You can move the extracted `aliyun` executable file to the `/usr/local/bin` directory or add it to the `$PATH`.

Download link: (3.0.81)
Download link: (3.0.85)

- [Mac](https://aliyuncli.alicdn.com/aliyun-cli-macosx-3.0.81-amd64.tgz)
- [Linux](https://aliyuncli.alicdn.com/aliyun-cli-linux-3.0.81-amd64.tgz)
- [Windows (64 bit)](https://aliyuncli.alicdn.com/aliyun-cli-windows-3.0.81-amd64.zip)
- [Mac](https://aliyuncli.alicdn.com/aliyun-cli-macosx-3.0.85-amd64.tgz)
- [Linux](https://aliyuncli.alicdn.com/aliyun-cli-linux-3.0.85-amd64.tgz)
- [Windows (64 bit)](https://aliyuncli.alicdn.com/aliyun-cli-windows-3.0.85-amd64.zip)

- **Use brew**
If you have installed `brew` in your computer, you can use it to install Alibaba Cloud CLI as following:
Expand Down
2 changes: 1 addition & 1 deletion aliyun-openapi-meta
4 changes: 2 additions & 2 deletions cli/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ func (c *Command) executeInner(ctx *Context, args []string) error {
}

func (c *Command) processError(ctx *Context, err error) {
Errorf(ctx.Writer(), "ERROR: %s\n", err.Error())
Errorf(ctx.Stderr(), "ERROR: %s\n", err.Error())
if e, ok := err.(SuggestibleError); ok {
PrintSuggestions(ctx, i18n.GetLanguage(), e.GetSuggestions())
Exit(2)
return
}
if e, ok := err.(ErrorWithTip); ok {
Noticef(ctx.Writer(), "\n%s\n", e.GetTip(i18n.GetLanguage()))
Noticef(ctx.Stderr(), "\n%s\n", e.GetTip(i18n.GetLanguage()))
Exit(3)
return
}
Expand Down
4 changes: 2 additions & 2 deletions cli/command_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func (c *Command) PrintFlags(ctx *Context) {
}

func (c *Command) PrintFailed(ctx *Context, err error, suggestion string) {
Errorf(ctx.Writer(), "ERROR: %v\n", err)
Printf(ctx.Writer(), "%s\n", suggestion)
Errorf(ctx.Stderr(), "ERROR: %v\n", err)
Printf(ctx.Stderr(), "%s\n", suggestion)
}

func (c *Command) PrintTail(ctx *Context) {
Expand Down
14 changes: 12 additions & 2 deletions cli/command_help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (

func TestCmdPrint(t *testing.T) {
w := new(bytes.Buffer)
ctx := NewCommandContext(w)
stderr := new(bytes.Buffer)
ctx := NewCommandContext(w, stderr)
c := &Command{
Name: "aliyun",
EnableUnknownFlag: true,
Expand All @@ -44,19 +45,23 @@ func TestCmdPrint(t *testing.T) {

//PrintUsage
w.Reset()
stderr.Reset()
c.PrintUsage(ctx)
assert.Equal(t, "\nUsage:\n aliyun [subcmd]\n", w.String())
w.Reset()
stderr.Reset()
c.Usage = ""
assert.Empty(t, w.String())

//PrintSample
w.Reset()
stderr.Reset()
c.PrintSample(ctx)
assert.Equal(t, "\nSample:\n aliyun oss\n", w.String())

//PrintSubCommands
w.Reset()
stderr.Reset()
subcmd := &Command{
Name: "oss",
SuggestDistance: 2,
Expand All @@ -72,24 +77,29 @@ func TestCmdPrint(t *testing.T) {

//PrintFlags
w.Reset()
stderr.Reset()
c.PrintFlags(ctx)
assert.Empty(t, w.String())
c.flags.flags = []*Flag{&Flag{Name: "output", Shorthand: 'o'}}
w.Reset()
stderr.Reset()
c.PrintFlags(ctx)
assert.Equal(t, "\nFlags:\n", w.String())
w.Reset()
stderr.Reset()
ctx.flags.flags = []*Flag{&Flag{Name: "output", Shorthand: 'o', Short: i18n.T("o test", "")}, &Flag{Name: "filter", Short: i18n.T("", "")}, &Flag{Name: "hidden", Hidden: true}}
c.PrintFlags(ctx)
assert.Equal(t, "\nFlags:\n --output,-o o test\n --filter \n", w.String())

//PrintFailed
w.Reset()
stderr.Reset()
c.PrintFailed(ctx, errors.New("you failed"), "come on again")
assert.Equal(t, "\x1b[1;31mERROR: you failed\n\x1b[0mcome on again\n", w.String())
assert.Equal(t, "\x1b[1;31mERROR: you failed\n\x1b[0mcome on again\n", stderr.String())

//PrintTail
w.Reset()
stderr.Reset()
c.PrintTail(ctx)
assert.Equal(t, "\nUse `aliyun --help` for more information.\n", w.String())
}
19 changes: 12 additions & 7 deletions cli/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func TestCommand(t *testing.T) {

//ExecuteComplete
w := new(bytes.Buffer)
ctx := NewCommandContext(w)
stderr := new(bytes.Buffer)
ctx := NewCommandContext(w, stderr)
ctx.completion = new(Completion)
ctx.completion.Current = "--f"
ctx.flags.flags = append(ctx.flags.flags, []*Flag{
Expand Down Expand Up @@ -192,7 +193,8 @@ func TestGetSubCommand(t *testing.T) {

func TestExecute(t *testing.T) {
buf := new(bytes.Buffer)
ctx := NewCommandContext(buf)
buf2 := new(bytes.Buffer)
ctx := NewCommandContext(buf, buf2)

cmd := newAliyunCmd()
subCmd := newTestCmd()
Expand All @@ -204,25 +206,27 @@ func TestExecute(t *testing.T) {
DisableExitCode()
defer EnableExitCode()
cmd.Execute(ctx, []string{})
assert.Equal(t, "\x1b[1;31mERROR: 'test' is not a vaild command\n\x1b[0m", buf.String())
assert.Equal(t, "\x1b[1;31mERROR: 'test' is not a vaild command\n\x1b[0m", buf2.String())
}

func TestProcessError(t *testing.T) {
DisableExitCode()
defer EnableExitCode()
cmd := newAliyunCmd()
buf := new(bytes.Buffer)
ctx := NewCommandContext(buf)
buf2 := new(bytes.Buffer)
ctx := NewCommandContext(buf, buf2)
e := errors.New("test error tip")
err := NewErrorWithTip(e, "")
cmd.processError(ctx, err)
assert.Equal(t, "\x1b[1;31mERROR: test error tip\n\x1b[0m\x1b[1;33m\n\n\x1b[0m", buf.String())
assert.Equal(t, "\x1b[1;31mERROR: test error tip\n\x1b[0m\x1b[1;33m\n\n\x1b[0m", buf2.String())
}

func TestExecuteHelp(t *testing.T) {
cmd := newAliyunCmd()
buf := new(bytes.Buffer)
ctx := NewCommandContext(buf)
buf2 := new(bytes.Buffer)
ctx := NewCommandContext(buf, buf2)
cmd.Help = func(ctx *Context, args []string) error {
fmt.Fprint(ctx.Writer(), "test execute help")
return nil
Expand All @@ -231,11 +235,12 @@ func TestExecuteHelp(t *testing.T) {
assert.Equal(t, "test execute help", buf.String())

buf.Reset()
buf2.Reset()
DisableExitCode()
defer EnableExitCode()
cmd.Help = func(ctx *Context, args []string) error {
return errors.New("test help error")
}
cmd.executeHelp(ctx, nil)
assert.Equal(t, "\x1b[1;31mERROR: test help error\n\x1b[0m", buf.String())
assert.Equal(t, "\x1b[1;31mERROR: test help error\n\x1b[0m", buf2.String())
}
17 changes: 8 additions & 9 deletions cli/completion_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package cli

import (
"fmt"
"io"

"github.com/aliyun/aliyun-cli/i18n"
)
Expand Down Expand Up @@ -44,9 +43,9 @@ func NewAutoCompleteCommand() *Command {
// fmt.Printf("zshInstaller: %s\n", f)
//}
if uninstallFlag.IsAssigned() {
uninstallCompletion(ctx.Writer(), "aliyun")
uninstallCompletion(ctx, "aliyun")
} else {
installCompletion(ctx.Writer(), "aliyun")
installCompletion(ctx, "aliyun")
}
return nil
},
Expand All @@ -55,32 +54,32 @@ func NewAutoCompleteCommand() *Command {
return cmd
}

func installCompletion(w io.Writer, cmd string) {
func installCompletion(ctx *Context, cmd string) {
bin, err := getBinaryPath()
if err != nil {
Errorf(w, "can't get binary path %s", err)
Errorf(ctx.Stderr(), "can't get binary path %s", err)
return
}

for _, i := range completionInstallers() {
err := i.Install(cmd, bin)
if err != nil {
Errorf(w, "install completion failed for %s %s\n", bin, err)
Errorf(ctx.Stderr(), "install completion failed for %s %s\n", bin, err)
}
}
}

func uninstallCompletion(w io.Writer, cmd string) {
func uninstallCompletion(ctx *Context, cmd string) {
bin, err := hookGetBinaryPath(getBinaryPath)()
if err != nil {
Errorf(w, "can't get binary path %s", err)
Errorf(ctx.Stderr(), "can't get binary path %s", err)
return
}

for _, i := range completionInstallers() {
err := i.Uninstall(cmd, bin)
if err != nil {
Errorf(w, "uninstall %s failed\n", err)
Errorf(ctx.Stderr(), "uninstall %s failed\n", err)
}
}
}
Expand Down
18 changes: 11 additions & 7 deletions cli/completion_installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ func TestCompletionInstallers(t *testing.T) {
}
func TestCompletion(t *testing.T) {
w := new(bytes.Buffer)
installCompletion(w, "is this a cmd?")
stderr := new(bytes.Buffer)
ctx := NewCommandContext(w, stderr)
installCompletion(ctx, "is this a cmd?")
assert.Empty(t, w.String())
}

Expand All @@ -114,9 +116,9 @@ func TestNewAutoCompleteCommand(t *testing.T) {
Usage: "auto-completion [--uninstall]",
Run: func(ctx *Context, args []string) error {
if uninstallFlag.IsAssigned() {
uninstallCompletion(ctx.Writer(), "aliyun")
uninstallCompletion(ctx, "aliyun")
} else {
installCompletion(ctx.Writer(), "aliyun")
installCompletion(ctx, "aliyun")
}
return nil
},
Expand All @@ -125,14 +127,14 @@ func TestNewAutoCompleteCommand(t *testing.T) {
cmd := NewAutoCompleteCommand()
assert.ObjectsAreEqualValues(excmd, cmd)
w := new(bytes.Buffer)
ctx := NewCommandContext(w)
stderr := new(bytes.Buffer)
ctx := NewCommandContext(w, stderr)
err := cmd.Run(ctx, []string{})
assert.Nil(t, err)
assert.Empty(t, w.String())
}

func TestUninstallCompletion(t *testing.T) {

orighookGetBinaryPath := hookGetBinaryPath
defer func() {
hookGetBinaryPath = orighookGetBinaryPath
Expand All @@ -144,6 +146,8 @@ func TestUninstallCompletion(t *testing.T) {
}

w := new(bytes.Buffer)
uninstallCompletion(w, "aliyun")
assert.Equal(t, "\x1b[1;31mcan't get binary path path error\x1b[0m", w.String())
stderr := new(bytes.Buffer)
ctx := NewCommandContext(w, stderr)
uninstallCompletion(ctx, "aliyun")
assert.Equal(t, "\x1b[1;31mcan't get binary path path error\x1b[0m", stderr.String())
}
Loading

0 comments on commit abf5e81

Please sign in to comment.