Skip to content

Commit 0e4ef9e

Browse files
authored
Merge pull request #61 from aliyun/pre-release
Pre release
2 parents 90e4308 + 9cd7005 commit 0e4ef9e

Some content is hidden

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

52 files changed

+2176
-659
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: go
33
sudo: true
44

55
go:
6-
- 1.8.x
6+
- 1.10.x
77

88
branches:
99
only:

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
[[constraint]]
2929
name = "github.com/aliyun/alibaba-cloud-sdk-go"
30-
version = "1.9.5"
30+
branch = "master"
3131

3232
[[constraint]]
3333
name = "github.com/aliyun/aliyun-oss-go-sdk"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export VERSION=3.0.1
1+
export VERSION=3.0.2
22
export RELEASE_PATH="releases/aliyun-cli-${VERSION}"
33

44
all: build

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ You can install Alibaba Cloud CLI either through the installer or the source cod
2323

2424
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`.
2525

26-
Download link: (3.0.1)
26+
Download link: (3.0.2)
2727

28-
- [Mac](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-macosx-3.0.1-amd64.tgz)
29-
- [Linux](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-linux-3.0.1-amd64.tgz)
30-
- [Windows (64 bit)](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-windows-3.0.1-amd64.zip)
28+
- [Mac](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-macosx-3.0.2-amd64.tgz)
29+
- [Linux](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-linux-3.0.2-amd64.tgz)
30+
- [Windows (64 bit)](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-windows-3.0.2-amd64.zip)
3131

3232
- **Compile source code**
3333

README_zh.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222

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

25-
下载链接如下 (3.0.1):
25+
下载链接如下 (3.0.2):
2626

27-
- [Mac](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-macosx-3.0.1-amd64.tgz)
28-
- [Linux](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-linux-3.0.1-amd64.tgz)
29-
- [Windows (64 bit)](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-windows-3.0.1-amd64.zip)
27+
- [Mac](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-macosx-3.0.2-amd64.tgz)
28+
- [Linux](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-linux-3.0.2-amd64.tgz)
29+
- [Windows (64 bit)](http://aliyun-cli.oss-cn-hangzhou.aliyuncs.com/aliyun-cli-windows-3.0.2-amd64.zip)
3030

3131
- **编译源码**
3232

cli/color.go

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
*/
44
package cli
55

6-
import "fmt"
6+
import (
7+
"fmt"
8+
"io"
9+
)
710

811
const (
912
ColorOff = "\033[0m" // Reset Color
@@ -86,42 +89,61 @@ const (
8689
ErrorColor = BRed
8790
)
8891

89-
func Debug(s string) {
90-
fmt.Print(DebugColor + s + ColorOff)
92+
var (
93+
withColor = true
94+
)
95+
96+
func EnableColor() {
97+
withColor = true
98+
}
99+
100+
func DisableColor() {
101+
withColor = false
102+
}
103+
104+
func colorized(color string, a ...interface{}) string {
105+
if withColor {
106+
return color + fmt.Sprint(a...) + ColorOff
107+
}
108+
return fmt.Sprint(a...)
109+
}
110+
111+
func Debug(w io.Writer, a ...interface{}) (n int, err error) {
112+
return Print(w, colorized(DebugColor, a...))
91113
}
92114

93-
func Info(s string) {
94-
fmt.Print(InfoColor + s + ColorOff)
115+
func Info(w io.Writer, a ...interface{}) (n int, err error) {
116+
return Print(w, colorized(InfoColor, a...))
95117
}
96118

97-
func Notice(s string) {
98-
fmt.Print(NoticeColor + s + ColorOff)
119+
func Notice(w io.Writer, a ...interface{}) (n int, err error) {
120+
return Print(w, colorized(NoticeColor, a...))
99121
}
100122

101-
func Warning(s string) {
102-
fmt.Print(WarningColor + s + ColorOff)
123+
func Warning(w io.Writer, a ...interface{}) (n int, err error) {
124+
return Print(w, colorized(WarningColor, a...))
103125
}
104126

105-
func Error(s string) {
106-
fmt.Print(ErrorColor + s + ColorOff)
127+
func Error(w io.Writer, a ...interface{}) (n int, err error) {
128+
return Print(w, colorized(ErrorColor, a...))
107129
}
108130

109-
func Debugf(format string, args ...interface{}) {
110-
Debug(fmt.Sprintf(format, args...))
131+
func Debugf(w io.Writer, format string, args ...interface{}) (n int, err error) {
132+
return Debug(w, fmt.Sprintf(format, args...))
111133
}
112134

113-
func Infof(format string, args ...interface{}) {
114-
Info(fmt.Sprintf(format, args...))
135+
func Infof(w io.Writer, format string, args ...interface{}) (n int, err error) {
136+
return Info(w, fmt.Sprintf(format, args...))
115137
}
116138

117-
func Noticef(format string, args ...interface{}) {
118-
Notice(fmt.Sprintf(format, args...))
139+
func Noticef(w io.Writer, format string, args ...interface{}) (n int, err error) {
140+
return Notice(w, fmt.Sprintf(format, args...))
119141
}
120142

121-
func Warningf(format string, args ...interface{}) {
122-
Warning(fmt.Sprintf(format, args...))
143+
func Warningf(w io.Writer, format string, args ...interface{}) (n int, err error) {
144+
return Warning(w, fmt.Sprintf(format, args...))
123145
}
124146

125-
func Errorf(format string, args ...interface{}) {
126-
Error(fmt.Sprintf(format, args...))
147+
func Errorf(w io.Writer, format string, args ...interface{}) (n int, err error) {
148+
return Error(w, fmt.Sprintf(format, args...))
127149
}

cli/command.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ func (c *Command) Flags() *FlagSet {
6363
return c.flags
6464
}
6565

66-
func (c *Command) Execute(args []string) {
67-
ctx := NewCommandContext()
68-
ctx.EnterCommand(c)
69-
ctx.completion = ParseCompletion()
66+
func (c *Command) Execute(ctx *Context, args []string) {
7067

7168
//
7269
// if completion
@@ -76,7 +73,7 @@ func (c *Command) Execute(args []string) {
7673

7774
err := c.executeInner(ctx, args)
7875
if err != nil {
79-
c.processError(err)
76+
c.processError(ctx, err)
8077
}
8178
}
8279

@@ -121,10 +118,10 @@ func (c *Command) ExecuteComplete(ctx *Context, args []string) {
121118
if f.Hidden {
122119
continue
123120
}
124-
if !strings.HasPrefix("--" + f.Name, ctx.completion.Current) {
121+
if !strings.HasPrefix("--"+f.Name, ctx.completion.Current) {
125122
continue
126123
}
127-
fmt.Printf("--%s\n", f.Name)
124+
Printf(ctx.Writer(), "--%s\n", f.Name)
128125
}
129126
} else {
130127
for _, sc := range c.subCommands {
@@ -134,7 +131,7 @@ func (c *Command) ExecuteComplete(ctx *Context, args []string) {
134131
if !strings.HasPrefix(sc.Name, ctx.completion.Current) {
135132
continue
136133
}
137-
fmt.Printf("%s\n", sc.Name)
134+
Printf(ctx.Writer(), "%s\n", sc.Name)
138135
}
139136
}
140137
}
@@ -192,7 +189,7 @@ func (c *Command) executeInner(ctx *Context, args []string) error {
192189
return err
193190
}
194191

195-
if HelpFlag.IsAssigned() {
192+
if HelpFlag(ctx.Flags()).IsAssigned() {
196193
ctx.help = true
197194
}
198195
callArgs := make([]string, 0)
@@ -211,7 +208,7 @@ func (c *Command) executeInner(ctx *Context, args []string) error {
211208
if c.AutoComplete != nil {
212209
ss := c.AutoComplete(ctx, callArgs)
213210
for _, s := range ss {
214-
fmt.Printf("%s\n", s)
211+
Printf(ctx.Writer(), "%s\n", s)
215212
}
216213
} else {
217214
c.ExecuteComplete(ctx, callArgs)
@@ -230,30 +227,33 @@ func (c *Command) executeInner(ctx *Context, args []string) error {
230227
}
231228
}
232229

233-
func (c *Command) processError(err error) {
234-
Errorf("ERROR: %s\n", err.Error())
230+
func (c *Command) processError(ctx *Context, err error) {
231+
Errorf(ctx.Writer(), "ERROR: %s\n", err.Error())
235232
if e, ok := err.(SuggestibleError); ok {
236-
PrintSuggestions(i18n.GetLanguage(), e.GetSuggestions())
233+
PrintSuggestions(ctx, i18n.GetLanguage(), e.GetSuggestions())
234+
Exit(2)
237235
return
238236
}
239237
if e, ok := err.(ErrorWithTip); ok {
240-
Noticef("\n%s\n", e.GetTip(i18n.GetLanguage()))
238+
Noticef(ctx.Writer(), "\n%s\n", e.GetTip(i18n.GetLanguage()))
239+
Exit(3)
241240
return
242241
}
242+
Exit(1)
243243
}
244244

245245
func (c *Command) executeHelp(ctx *Context, args []string) {
246246
if c.Help != nil {
247247
err := c.Help(ctx, args)
248248
if err != nil {
249-
c.processError(err)
249+
c.processError(ctx, err)
250250
}
251251
return
252252
}
253253

254-
c.PrintHead()
255-
c.PrintUsage()
256-
c.PrintSubCommands()
254+
c.PrintHead(ctx)
255+
c.PrintUsage(ctx)
256+
c.PrintSubCommands(ctx)
257257
c.PrintFlags(ctx)
258-
c.PrintTail()
258+
c.PrintTail(ctx)
259259
}

cli/command_help.go

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,34 @@ package cli
22

33
import (
44
"fmt"
5-
"os"
65
"text/tabwriter"
76
)
87

9-
func (c *Command) PrintHead() {
10-
fmt.Printf("%s\n", c.Short.Text())
8+
func (c *Command) PrintHead(ctx *Context) {
9+
Printf(ctx.Writer(), "%s\n", c.Short.Text())
1110
//if c.Long != nil {
1211
// fmt.Printf("\n%s\n", c.Long.Text())
1312
//}
1413
}
1514

16-
func (c *Command) PrintUsage() {
15+
func (c *Command) PrintUsage(ctx *Context) {
1716
if c.Usage != "" {
18-
fmt.Printf("\nUsage:\n %s\n", c.GetUsageWithParent())
17+
Printf(ctx.Writer(), "\nUsage:\n %s\n", c.GetUsageWithParent())
1918
} else {
20-
c.PrintSubCommands()
19+
c.PrintSubCommands(ctx)
2120
}
2221
}
2322

24-
func (c *Command) PrintSample() {
23+
func (c *Command) PrintSample(ctx *Context) {
2524
if c.Sample != "" {
26-
fmt.Printf("\nSample:\n %s\n", c.Sample)
25+
Printf(ctx.Writer(), "\nSample:\n %s\n", c.Sample)
2726
}
2827
}
2928

30-
func (c *Command) PrintSubCommands() {
29+
func (c *Command) PrintSubCommands(ctx *Context) {
3130
if len(c.subCommands) > 0 {
32-
fmt.Printf("\nCommands:\n")
33-
34-
w := tabwriter.NewWriter(os.Stdout, 8, 0, 1, ' ', 0)
31+
Printf(ctx.Writer(), "\nCommands:\n")
32+
w := tabwriter.NewWriter(ctx.Writer(), 8, 0, 1, ' ', 0)
3533
for _, cmd := range c.subCommands {
3634
if cmd.Hidden {
3735
continue
@@ -46,9 +44,8 @@ func (c *Command) PrintFlags(ctx *Context) {
4644
if len(c.Flags().Flags()) == 0 {
4745
return
4846
}
49-
50-
fmt.Printf("\nFlags:\n")
51-
w := tabwriter.NewWriter(os.Stdout, 8, 0, 1, ' ', 0)
47+
Printf(ctx.Writer(), "\nFlags:\n")
48+
w := tabwriter.NewWriter(ctx.Writer(), 8, 0, 1, ' ', 0)
5249
fs := c.Flags()
5350
if ctx != nil {
5451
fs = ctx.Flags()
@@ -66,11 +63,11 @@ func (c *Command) PrintFlags(ctx *Context) {
6663
w.Flush()
6764
}
6865

69-
func (c *Command) PrintFailed(err error, suggestion string) {
70-
Errorf("ERROR: %v\n", err)
71-
fmt.Printf("%s\n", suggestion)
66+
func (c *Command) PrintFailed(ctx *Context, err error, suggestion string) {
67+
Errorf(ctx.Writer(), "ERROR: %v\n", err)
68+
Printf(ctx.Writer(), "%s\n", suggestion)
7269
}
7370

74-
func (c *Command) PrintTail() {
75-
fmt.Printf("\nUse `%s --help` for more information.\n", c.Name)
71+
func (c *Command) PrintTail(ctx *Context) {
72+
Printf(ctx.Writer(), "\nUse `%s --help` for more information.\n", c.Name)
7673
}

cli/completion.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,20 @@ type Completion struct {
1717
point int
1818
}
1919

20-
func ParseCompletion() *Completion {
21-
line := os.Getenv("COMP_LINE")
20+
func ParseCompletionForShell() *Completion {
21+
return ParseCompletion(os.Getenv("COMP_LINE"), os.Getenv("COMP_POINT"))
22+
}
23+
24+
func ParseCompletion(line, point string) *Completion {
2225
if line == "" {
2326
return nil
2427
}
25-
p, _ := strconv.Atoi(os.Getenv("COMP_POINT"))
28+
29+
p, err := strconv.Atoi(point)
30+
31+
if err != nil {
32+
return nil
33+
}
2634

2735
if p >= len(line) {
2836
p = len(line)

0 commit comments

Comments
 (0)