Skip to content
This repository has been archived by the owner on Apr 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #28 from containous/fix-empty-args
Browse files Browse the repository at this point in the history
fix splitArgs on empty args
  • Loading branch information
emilevauge committed Jun 2, 2016
2 parents 68129e4 + 3fa6d1c commit b98687d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flaeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ func (f *Flaeg) Parse(cmd *Command) (*Command, error) {

//splitArgs takes args (type []string) and return command ("" if rootCommand) and command's args
func splitArgs(args []string) (string, []string) {
if len(args) >= 1 && string(args[0][0]) != "-" {
if len(args) >= 1 && len(args[0]) >= 1 && string(args[0][0]) != "-" {
if len(args) == 1 {
return strings.ToLower(args[0]), []string{}
}
Expand Down
2 changes: 2 additions & 0 deletions flaeg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2576,13 +2576,15 @@ func TestArgsToLower(t *testing.T) {

func TestSplitArgs(t *testing.T) {
inSlice := [][]string{
[]string{""},
[]string{"-a"},
[]string{"--arg=toto", "-atata"},
[]string{"cmd"},
[]string{"cmd", "-a"},
[]string{"cmd", "--arg=toto", "-atata"},
}
checkSlice := [][]string{
[]string{"", ""},
[]string{"", "-a"},
[]string{"", "--arg=toto", "-atata"},
[]string{"cmd"},
Expand Down

0 comments on commit b98687d

Please sign in to comment.