]> gitweb.factorcode.org Git - factor.git/commitdiff
command-line: make script and -run= param behave similarly.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 25 Sep 2014 19:02:23 +0000 (12:02 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 26 Sep 2014 04:08:15 +0000 (21:08 -0700)
basis/command-line/command-line-tests.factor [new file with mode: 0644]
basis/command-line/command-line.factor

diff --git a/basis/command-line/command-line-tests.factor b/basis/command-line/command-line-tests.factor
new file mode 100644 (file)
index 0000000..01099ae
--- /dev/null
@@ -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
index 8f38208c89859feb852442a685d849acb78ef20b..37511dae90c5473d96da4c22cdd06aebff611658 100644 (file)
@@ -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