command-line.startup: adding version argument.

$ ./factor -version
Factor 0.99
clean-macosx-x86-64
John Benediktsson 2019-11-06 08:12:39 -08:00
parent 745840dfca
commit 83fd6b65e0
1 changed files with 25 additions and 17 deletions

View File

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