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.
! 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 ;