diff --git a/basis/command-line/command-line-tests.factor b/basis/command-line/command-line-tests.factor new file mode 100644 index 0000000000..01099ae19d --- /dev/null +++ b/basis/command-line/command-line-tests.factor @@ -0,0 +1,32 @@ +USING: namespaces splitting tools.test ; +IN: command-line + +{ f { "a" "b" "c" } } [ + { "-run=test-voc" "a" "b" "c" } parse-command-line + script get command-line get +] unit-test + +{ f { "-a" "b" "c" } } [ + { "-run=test-voc" "-a" "b" "c" } parse-command-line + script get command-line get +] unit-test + +{ f { "a" "-b" "c" } } [ + { "-run=test-voc" "a" "-b" "c" } parse-command-line + script get command-line get +] unit-test + +{ f { "a" "b" "-c" } } [ + { "-run=test-voc" "a" "b" "-c" } parse-command-line + script get command-line get +] unit-test + +{ "a" { "b" "c" } } [ + { "a" "b" "c" } parse-command-line + script get command-line get +] unit-test + +{ "a" { "b" "c" } } [ + { "-foo" "a" "b" "c" } parse-command-line + script get command-line get +] unit-test diff --git a/basis/command-line/command-line.factor b/basis/command-line/command-line.factor index 8f38208c89..37511dae90 100644 --- a/basis/command-line/command-line.factor +++ b/basis/command-line/command-line.factor @@ -62,18 +62,21 @@ SYMBOL: command-line [ source-file main>> [ execute( -- ) ] when* ] bi ] with-variable ; -: (parse-command-line) ( run? args -- ) - [ command-line off script off drop ] [ - unclip "-" ?head - [ param (parse-command-line) ] - [ - rot [ prefix f ] when +: (parse-command-line) ( args -- ) + [ + unclip "-" ?head [ + [ param ] [ "run=" head? ] bi + [ command-line set ] + [ (parse-command-line) ] if + ] [ script set command-line set ] if - ] if-empty ; + ] unless-empty ; : parse-command-line ( args -- ) - [ [ "-run=" head? ] any? ] keep (parse-command-line) ; + command-line off + script off + (parse-command-line) ; SYMBOL: main-vocab-hook