Skip to content

Commit

Permalink
Merge pull request #61 from aliyun/pre-release
Browse files Browse the repository at this point in the history
Pre release
  • Loading branch information
jxyowen authored May 13, 2018
2 parents 90e4308 + 9cd7005 commit 0e4ef9e
Show file tree
Hide file tree
Showing 52 changed files with 2,176 additions and 659 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: go
sudo: true

go:
- 1.8.x
- 1.10.x

branches:
only:
Expand Down
2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

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

[[constraint]]
name = "github.com/aliyun/aliyun-oss-go-sdk"
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.1
export VERSION=3.0.2
export RELEASE_PATH="releases/aliyun-cli-${VERSION}"

all: build
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ You can install Alibaba Cloud CLI either through the installer or the source cod

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.1)
Download link: (3.0.2)

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

- **Compile source code**

Expand Down
8 changes: 4 additions & 4 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

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

下载链接如下 (3.0.1):
下载链接如下 (3.0.2):

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

- **编译源码**

Expand Down
64 changes: 43 additions & 21 deletions cli/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*/
package cli

import "fmt"
import (
"fmt"
"io"
)

const (
ColorOff = "\033[0m" // Reset Color
Expand Down Expand Up @@ -86,42 +89,61 @@ const (
ErrorColor = BRed
)

func Debug(s string) {
fmt.Print(DebugColor + s + ColorOff)
var (
withColor = true
)

func EnableColor() {
withColor = true
}

func DisableColor() {
withColor = false
}

func colorized(color string, a ...interface{}) string {
if withColor {
return color + fmt.Sprint(a...) + ColorOff
}
return fmt.Sprint(a...)
}

func Debug(w io.Writer, a ...interface{}) (n int, err error) {
return Print(w, colorized(DebugColor, a...))
}

func Info(s string) {
fmt.Print(InfoColor + s + ColorOff)
func Info(w io.Writer, a ...interface{}) (n int, err error) {
return Print(w, colorized(InfoColor, a...))
}

func Notice(s string) {
fmt.Print(NoticeColor + s + ColorOff)
func Notice(w io.Writer, a ...interface{}) (n int, err error) {
return Print(w, colorized(NoticeColor, a...))
}

func Warning(s string) {
fmt.Print(WarningColor + s + ColorOff)
func Warning(w io.Writer, a ...interface{}) (n int, err error) {
return Print(w, colorized(WarningColor, a...))
}

func Error(s string) {
fmt.Print(ErrorColor + s + ColorOff)
func Error(w io.Writer, a ...interface{}) (n int, err error) {
return Print(w, colorized(ErrorColor, a...))
}

func Debugf(format string, args ...interface{}) {
Debug(fmt.Sprintf(format, args...))
func Debugf(w io.Writer, format string, args ...interface{}) (n int, err error) {
return Debug(w, fmt.Sprintf(format, args...))
}

func Infof(format string, args ...interface{}) {
Info(fmt.Sprintf(format, args...))
func Infof(w io.Writer, format string, args ...interface{}) (n int, err error) {
return Info(w, fmt.Sprintf(format, args...))
}

func Noticef(format string, args ...interface{}) {
Notice(fmt.Sprintf(format, args...))
func Noticef(w io.Writer, format string, args ...interface{}) (n int, err error) {
return Notice(w, fmt.Sprintf(format, args...))
}

func Warningf(format string, args ...interface{}) {
Warning(fmt.Sprintf(format, args...))
func Warningf(w io.Writer, format string, args ...interface{}) (n int, err error) {
return Warning(w, fmt.Sprintf(format, args...))
}

func Errorf(format string, args ...interface{}) {
Error(fmt.Sprintf(format, args...))
func Errorf(w io.Writer, format string, args ...interface{}) (n int, err error) {
return Error(w, fmt.Sprintf(format, args...))
}
38 changes: 19 additions & 19 deletions cli/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ func (c *Command) Flags() *FlagSet {
return c.flags
}

func (c *Command) Execute(args []string) {
ctx := NewCommandContext()
ctx.EnterCommand(c)
ctx.completion = ParseCompletion()
func (c *Command) Execute(ctx *Context, args []string) {

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

err := c.executeInner(ctx, args)
if err != nil {
c.processError(err)
c.processError(ctx, err)
}
}

Expand Down Expand Up @@ -121,10 +118,10 @@ func (c *Command) ExecuteComplete(ctx *Context, args []string) {
if f.Hidden {
continue
}
if !strings.HasPrefix("--" + f.Name, ctx.completion.Current) {
if !strings.HasPrefix("--"+f.Name, ctx.completion.Current) {
continue
}
fmt.Printf("--%s\n", f.Name)
Printf(ctx.Writer(), "--%s\n", f.Name)
}
} else {
for _, sc := range c.subCommands {
Expand All @@ -134,7 +131,7 @@ func (c *Command) ExecuteComplete(ctx *Context, args []string) {
if !strings.HasPrefix(sc.Name, ctx.completion.Current) {
continue
}
fmt.Printf("%s\n", sc.Name)
Printf(ctx.Writer(), "%s\n", sc.Name)
}
}
}
Expand Down Expand Up @@ -192,7 +189,7 @@ func (c *Command) executeInner(ctx *Context, args []string) error {
return err
}

if HelpFlag.IsAssigned() {
if HelpFlag(ctx.Flags()).IsAssigned() {
ctx.help = true
}
callArgs := make([]string, 0)
Expand All @@ -211,7 +208,7 @@ func (c *Command) executeInner(ctx *Context, args []string) error {
if c.AutoComplete != nil {
ss := c.AutoComplete(ctx, callArgs)
for _, s := range ss {
fmt.Printf("%s\n", s)
Printf(ctx.Writer(), "%s\n", s)
}
} else {
c.ExecuteComplete(ctx, callArgs)
Expand All @@ -230,30 +227,33 @@ func (c *Command) executeInner(ctx *Context, args []string) error {
}
}

func (c *Command) processError(err error) {
Errorf("ERROR: %s\n", err.Error())
func (c *Command) processError(ctx *Context, err error) {
Errorf(ctx.Writer(), "ERROR: %s\n", err.Error())
if e, ok := err.(SuggestibleError); ok {
PrintSuggestions(i18n.GetLanguage(), e.GetSuggestions())
PrintSuggestions(ctx, i18n.GetLanguage(), e.GetSuggestions())
Exit(2)
return
}
if e, ok := err.(ErrorWithTip); ok {
Noticef("\n%s\n", e.GetTip(i18n.GetLanguage()))
Noticef(ctx.Writer(), "\n%s\n", e.GetTip(i18n.GetLanguage()))
Exit(3)
return
}
Exit(1)
}

func (c *Command) executeHelp(ctx *Context, args []string) {
if c.Help != nil {
err := c.Help(ctx, args)
if err != nil {
c.processError(err)
c.processError(ctx, err)
}
return
}

c.PrintHead()
c.PrintUsage()
c.PrintSubCommands()
c.PrintHead(ctx)
c.PrintUsage(ctx)
c.PrintSubCommands(ctx)
c.PrintFlags(ctx)
c.PrintTail()
c.PrintTail(ctx)
}
37 changes: 17 additions & 20 deletions cli/command_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,34 @@ package cli

import (
"fmt"
"os"
"text/tabwriter"
)

func (c *Command) PrintHead() {
fmt.Printf("%s\n", c.Short.Text())
func (c *Command) PrintHead(ctx *Context) {
Printf(ctx.Writer(), "%s\n", c.Short.Text())
//if c.Long != nil {
// fmt.Printf("\n%s\n", c.Long.Text())
//}
}

func (c *Command) PrintUsage() {
func (c *Command) PrintUsage(ctx *Context) {
if c.Usage != "" {
fmt.Printf("\nUsage:\n %s\n", c.GetUsageWithParent())
Printf(ctx.Writer(), "\nUsage:\n %s\n", c.GetUsageWithParent())
} else {
c.PrintSubCommands()
c.PrintSubCommands(ctx)
}
}

func (c *Command) PrintSample() {
func (c *Command) PrintSample(ctx *Context) {
if c.Sample != "" {
fmt.Printf("\nSample:\n %s\n", c.Sample)
Printf(ctx.Writer(), "\nSample:\n %s\n", c.Sample)
}
}

func (c *Command) PrintSubCommands() {
func (c *Command) PrintSubCommands(ctx *Context) {
if len(c.subCommands) > 0 {
fmt.Printf("\nCommands:\n")

w := tabwriter.NewWriter(os.Stdout, 8, 0, 1, ' ', 0)
Printf(ctx.Writer(), "\nCommands:\n")
w := tabwriter.NewWriter(ctx.Writer(), 8, 0, 1, ' ', 0)
for _, cmd := range c.subCommands {
if cmd.Hidden {
continue
Expand All @@ -46,9 +44,8 @@ func (c *Command) PrintFlags(ctx *Context) {
if len(c.Flags().Flags()) == 0 {
return
}

fmt.Printf("\nFlags:\n")
w := tabwriter.NewWriter(os.Stdout, 8, 0, 1, ' ', 0)
Printf(ctx.Writer(), "\nFlags:\n")
w := tabwriter.NewWriter(ctx.Writer(), 8, 0, 1, ' ', 0)
fs := c.Flags()
if ctx != nil {
fs = ctx.Flags()
Expand All @@ -66,11 +63,11 @@ func (c *Command) PrintFlags(ctx *Context) {
w.Flush()
}

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

func (c *Command) PrintTail() {
fmt.Printf("\nUse `%s --help` for more information.\n", c.Name)
func (c *Command) PrintTail(ctx *Context) {
Printf(ctx.Writer(), "\nUse `%s --help` for more information.\n", c.Name)
}
14 changes: 11 additions & 3 deletions cli/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ type Completion struct {
point int
}

func ParseCompletion() *Completion {
line := os.Getenv("COMP_LINE")
func ParseCompletionForShell() *Completion {
return ParseCompletion(os.Getenv("COMP_LINE"), os.Getenv("COMP_POINT"))
}

func ParseCompletion(line, point string) *Completion {
if line == "" {
return nil
}
p, _ := strconv.Atoi(os.Getenv("COMP_POINT"))

p, err := strconv.Atoi(point)

if err != nil {
return nil
}

if p >= len(line) {
p = len(line)
Expand Down
Loading

0 comments on commit 0e4ef9e

Please sign in to comment.