Skip to content

Commit

Permalink
Lowercase command name.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Oct 14, 2016
1 parent 1113767 commit a65b760
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ func (cmd *baseCmd) setErr(e error) {
}

func newBaseCmd(args []interface{}) baseCmd {
if len(args) > 0 {
// Cmd name is expected to be in lower case.
args[0] = internal.ToLower(args[0].(string))
}
return baseCmd{_args: args}
}

Expand Down
27 changes: 27 additions & 0 deletions internal/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package internal

func ToLower(s string) string {
if isLower(s) {
return s
}

b := make([]byte, len(s))
for i := range b {
c := s[i]
if c >= 'A' && c <= 'Z' {
c += 'a' - 'A'
}
b[i] = c
}
return string(b)
}

func isLower(s string) bool {
for i := 0; i < len(s); i++ {
c := s[i]
if c >= 'A' && c <= 'Z' {
return false
}
}
return true
}

0 comments on commit a65b760

Please sign in to comment.