]> gitweb.factorcode.org Git - factor.git/commitdiff
command-line.startup: adding version argument.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 6 Nov 2019 16:12:39 +0000 (08:12 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 6 Nov 2019 16:12:39 +0000 (08:12 -0800)
$ ./factor -version
Factor 0.99

basis/command-line/startup/startup.factor

index 5d5fca126cae3833f7ce5e625858f54bd5c33aee..3f976028a920582d5fc64472950fdfdf43d7c2bb 100644 (file)
@@ -1,14 +1,19 @@
 ! Copyright (C) 2011 Joe Groff.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: command-line eval io io.pathnames kernel namespaces
-sequences system vocabs.loader ;
+USING: combinators command-line eval io io.pathnames kernel
+namespaces system vocabs.loader ;
 IN: command-line.startup
 
-: cli-usage ( -- )
+: help? ( -- ? )
+    "help" get "h" get or
+    os windows? [ script get "/?" = or ] when ;
+
+: help. ( -- )
 "Usage: " write vm-path file-name write " [Factor arguments] [script] [script arguments]
 
 Factor arguments:
     -help               print this message and exit
+    -version            print the Factor version and exit
     -i=<image>          load Factor image file <image> (default " write vm-path file-stem write ".image)
     -run=<vocab>        run the MAIN: entry point of <vocab>
         -run=listener   run terminal listener
@@ -35,22 +40,25 @@ from within Factor for more information.
 
 " write ;
 
-: help? ( -- ? )
-    "help" get "h" get or
-    os windows? [ script get "/?" = or ] when ;
+: version? ( -- ? ) "version" get ;
+
+: version. ( -- ) "Factor " write vm-version print ;
 
 : command-line-startup ( -- )
-    (command-line) parse-command-line
-    help? [ cli-usage ] [
-        load-vocab-roots
-        run-user-init
-        "e" get script get or [
-            "e" get [ eval( -- ) ] when*
-            script get [ run-script ] when*
-        ] [
-            "run" get run
-        ] if
-    ] if
+    (command-line) parse-command-line {
+        { [ help? ] [ help. ] }
+        { [ version? ] [ version. ] }
+        [
+            load-vocab-roots
+            run-user-init
+            "e" get script get or [
+                "e" get [ eval( -- ) ] when*
+                script get [ run-script ] when*
+            ] [
+                "run" get run
+            ] if
+        ]
+    } cond
 
     output-stream get [ stream-flush ] when*
     0 exit ;