]> gitweb.factorcode.org Git - factor.git/commitdiff
command-line: interpret "-help" or "--help" and print a brief usage message with...
authorJoe Groff <arcata@gmail.com>
Fri, 19 Aug 2011 02:10:51 +0000 (19:10 -0700)
committerJoe Groff <arcata@gmail.com>
Fri, 19 Aug 2011 02:10:51 +0000 (19:10 -0700)
basis/bootstrap/finish-bootstrap.factor
basis/command-line/command-line.factor

index 387903d1e9d60968f2822e63fb6fbfc6d7041327..b64de97622ea720a5a77a3135a84ca2c85f5c44b 100644 (file)
@@ -4,19 +4,5 @@ namespaces eval kernel vocabs.loader io ;
 [
     boot
     do-startup-hooks
-    [
-        (command-line) parse-command-line
-        load-vocab-roots
-        run-user-init
-
-        "e" get script get or [
-            "e" get [ eval( -- ) ] when*
-            script get [ run-script ] when*
-        ] [
-            "run" get run
-        ] if
-
-        output-stream get [ stream-flush ] when*
-        0 exit
-    ] [ print-error 1 exit ] recover
+    [ command-line-startup ] [ print-error 1 exit ] recover
 ] set-startup-quot
index e902bbc396f3cb2d9b7a3d9e66f147055f98f2a4..eb0231c4c8ede0a6b2d0b48f81a1cf203db4cdcd 100644 (file)
@@ -3,7 +3,7 @@
 USING: init continuations hashtables io io.encodings.utf8
 io.files io.pathnames kernel kernel.private namespaces parser
 sequences source-files strings system splitting vocabs.loader
-alien.strings accessors ;
+alien.strings accessors eval ;
 IN: command-line
 
 SYMBOL: script
@@ -71,3 +71,39 @@ SYMBOL: main-vocab-hook
     ] bind ;
 
 [ default-cli-args ] "command-line" add-startup-hook
+
+: cli-usage ( -- )
+"""
+Usage: """ write vm file-name write """ [Factor arguments] [script] [script arguments]
+
+Common arguments:
+    -help            print this message and exit
+    -i=<image>       load Factor image file <image> (default """ write vm file-name write """.image)
+    -run=<vocab>     run the MAIN: entry point of <vocab>
+    -e=<code>        evaluate <code>
+    -quiet           suppress "Loading vocab.factor" messages
+    -no-user-init    suppress loading of .factor-rc
+
+Enter
+    "command-line" help
+from within Factor for more information.
+
+""" write ;
+
+: command-line-startup ( -- )
+    (command-line) parse-command-line
+    load-vocab-roots
+    run-user-init
+
+    "help" get "-help" get or "h" get or [ cli-usage ] [
+        "e" get script get or [
+            "e" get [ eval( -- ) ] when*
+            script get [ run-script ] when*
+        ] [
+            "run" get run
+        ] if
+    ] if
+
+    output-stream get [ stream-flush ] when*
+    0 exit ;
+