Skip to content

Commit

Permalink
Merge branch 'dev' into docs
Browse files Browse the repository at this point in the history
  • Loading branch information
WindomZ committed Jun 7, 2017
2 parents 9d3721b + d8d954c commit f1835b1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# go-commander

[![Build Status](https://travis-ci.org/WindomZ/go-commander.svg?branch=master)](https://travis-ci.org/WindomZ/go-commander)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://opensource.org/licenses/MIT)
[![Go Report Card](https://goreportcard.com/badge/github.com/WindomZ/go-commander)](https://goreportcard.com/report/github.com/WindomZ/go-commander)
[![Coverage Status](https://coveralls.io/repos/github/WindomZ/go-commander/badge.svg?branch=master)](https://coveralls.io/github/WindomZ/go-commander?branch=master)

The solution for building command shell programs,
> The solution for building command shell programs,
drive by <[docopt](https://github.com/docopt/docopt.go)>,
inspired by <[commander.js](https://github.com/tj/commander.js)>
![v1.2.0](https://img.shields.io/badge/version-v1.2.0-blue.svg)
![v1.2.2](https://img.shields.io/badge/version-v1.2.2-blue.svg)
![status](https://img.shields.io/badge/status-stable-green.svg)

## Features
Expand Down Expand Up @@ -280,6 +281,12 @@ $ calculator_example sum 10 , 20 , 30 , 40
- [gitdate](https://github.com/WindomZ/gitdate)
- [gituser](https://github.com/WindomZ/gituser)

## Development

I would **love** to hear what you think about `go-commander` on [issues page](https://github.com/WindomZ/go-commander/issues)

Make pull requests, report bugs, suggest ideas and discuss `go-commander`.

## License

The [MIT License](https://github.com/WindomZ/gitclone/blob/master/LICENSE)
The [MIT License](https://github.com/WindomZ/go-commander/blob/master/LICENSE)
6 changes: 3 additions & 3 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (c *_Command) init() *_Command {
} else if dir, err := os.Getwd(); err == nil {
name = path.Base(dir)
}
if len(name) == 0 {
if name = defineCommand(name); len(name) == 0 {
panicError("root command should not be empty")
}
c.Usage(name)
Expand Down Expand Up @@ -226,8 +226,8 @@ func (c *_Command) Action(action interface{}, keys ...[]string) Commander {
switch obj := c.last.(type) {
//case *_Command:
case *_Option:
obj.actor.Action(action, keys...)
if c.hasAction() {
if c.clone || c.actor.hasAction() {
obj.actor.Action(action, keys...)
return c
}
}
Expand Down
5 changes: 5 additions & 0 deletions regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import (
"strings"
)

// defineCommand define commands
func defineCommand(str string) string {
return regexp.MustCompile(`[A-Za-z0-9_-]+`).FindString(str)
}

// regexpCommand Regular screening out docopt commands
func regexpCommand(str string) []string {
return regexp.MustCompile(`[A-Za-z0-9_-]+`).FindAllString(
Expand Down

0 comments on commit f1835b1

Please sign in to comment.