diff --git a/parser.go b/parser.go index 8a2ce936..e9d99c60 100644 --- a/parser.go +++ b/parser.go @@ -8,6 +8,7 @@ import ( "os" "strconv" "strings" + "unicode" ) // A basic set implementation for strings. @@ -613,7 +614,7 @@ func (parser *arguments) parseCommandLine() (err error) { return } -//parses input for number menus +//parses input for number menus splitted by spaces or commas //supports individual selection: 1 2 3 4 //supports range selections: 1-4 10-20 //supports negation: ^1 ^1-4 @@ -629,7 +630,9 @@ func parseNumberMenu(input string) (intRanges, intRanges, stringSet, stringSet) otherInclude := make(stringSet) otherExclude := make(stringSet) - words := strings.Fields(input) + words := strings.FieldsFunc(input, func(c rune) bool { + return unicode.IsSpace(c) || c == ',' + }) for _, word := range words { var num1 int diff --git a/parser_test.go b/parser_test.go index 5aa57c67..b0c18c9c 100644 --- a/parser_test.go +++ b/parser_test.go @@ -65,6 +65,7 @@ func TestParseNumberMenu(t *testing.T) { "abort all none", "a-b ^a-b ^abort", "1\t2 3 4\t\t \t 5", + "1 2,3, 4, 5,6 ,7 ,8", "", " \t ", "A B C D E", @@ -78,6 +79,7 @@ func TestParseNumberMenu(t *testing.T) { {intRanges{}, intRanges{}, makeStringSet("abort", "all", "none"), make(stringSet)}, {intRanges{}, intRanges{}, makeStringSet("a-b"), makeStringSet("abort", "a-b")}, {intRanges{makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5)}, intRanges{}, make(stringSet), make(stringSet)}, + {intRanges{makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5), makeIntRange(6, 6), makeIntRange(7, 7), makeIntRange(8, 8)}, intRanges{}, make(stringSet), make(stringSet)}, {intRanges{}, intRanges{}, make(stringSet), make(stringSet)}, {intRanges{}, intRanges{}, make(stringSet), make(stringSet)}, {intRanges{}, intRanges{}, makeStringSet("a", "b", "c", "d", "e"), make(stringSet)},