command-line: save the executable in a variable so that people don't use (command-line) directly if possible.

db4
John Benediktsson 2014-12-23 08:12:31 -08:00
parent 25dd9f3abb
commit c0dda5c7e9
7 changed files with 37 additions and 25 deletions

View File

@ -4,7 +4,7 @@ vocabs.loader ;
[ [
boot boot
do-startup-hooks do-startup-hooks
(command-line) rest parse-command-line (command-line) parse-command-line
"run" get run "run" get run
output-stream get [ stream-flush ] when* output-stream get [ stream-flush ] when*
0 exit 0 exit

View File

@ -71,7 +71,7 @@ SYMBOL: bootstrap-time
strip-encodings strip-encodings
(command-line) rest parse-command-line (command-line) parse-command-line
! Set dll paths ! Set dll paths
os windows? [ "windows" require ] when os windows? [ "windows" require ] when

View File

@ -23,10 +23,17 @@ $nl
HELP: (command-line) HELP: (command-line)
{ $values { "args" "a sequence of strings" } } { $values { "args" "a sequence of strings" } }
{ $description "Outputs the command line parameters which were passed to the Factor VM on startup." } ; { $description "Outputs the raw command line parameters which were passed to the Factor VM on startup."
$nl
"We recommend using the " { $link executable } " and " { $link command-line } " symbols instead." } ;
HELP: command-line HELP: command-line
{ $var-description "When Factor is run with a script, this variable contains command line parameters which follow the name of the script on the command line. In deployed applications, it contains the entire command line. In all other cases it is set to " { $link f } "." } ; { $var-description "When Factor is run with a script, this variable contains the list of command line arguments which follow the name of the script on the command line. In deployed applications, it contains the full list of command line arguments. In all other cases it is set to " { $link f } "." }
{ $see-also executable } ;
HELP: executable
{ $var-description "Provides the path to the executable binary, typically Factor. However, in a deployed application this will be the path to the deployed binary that is being executed." }
{ $see-also command-line } ;
HELP: main-vocab-hook HELP: main-vocab-hook
{ $var-description "Global variable holding a quotation which outputs a vocabulary name. UI backends set this so that the UI can automatically start if the prerequisites are met (for example, " { $snippet "$DISPLAY" } " being set on X11)." } ; { $var-description "Global variable holding a quotation which outputs a vocabulary name. UI backends set this so that the UI can automatically start if the prerequisites are met (for example, " { $snippet "$DISPLAY" } " being set on X11)." } ;

View File

@ -1,32 +1,32 @@
USING: namespaces splitting tools.test ; USING: namespaces splitting tools.test ;
IN: command-line IN: command-line
{ f { "a" "b" "c" } } [ { "factor" f { "a" "b" "c" } } [
{ "-run=test-voc" "a" "b" "c" } parse-command-line { "factor" "-run=test-voc" "a" "b" "c" } parse-command-line
script get command-line get executable get script get command-line get
] unit-test ] unit-test
{ f { "-a" "b" "c" } } [ { "factor" f { "-a" "b" "c" } } [
{ "-run=test-voc" "-a" "b" "c" } parse-command-line { "factor" "-run=test-voc" "-a" "b" "c" } parse-command-line
script get command-line get executable get script get command-line get
] unit-test ] unit-test
{ f { "a" "-b" "c" } } [ { "factor" f { "a" "-b" "c" } } [
{ "-run=test-voc" "a" "-b" "c" } parse-command-line { "factor" "-run=test-voc" "a" "-b" "c" } parse-command-line
script get command-line get executable get script get command-line get
] unit-test ] unit-test
{ f { "a" "b" "-c" } } [ { "factor" f { "a" "b" "-c" } } [
{ "-run=test-voc" "a" "b" "-c" } parse-command-line { "factor" "-run=test-voc" "a" "b" "-c" } parse-command-line
script get command-line get executable get script get command-line get
] unit-test ] unit-test
{ "a" { "b" "c" } } [ { "factor" "a" { "b" "c" } } [
{ "a" "b" "c" } parse-command-line { "factor" "a" "b" "c" } parse-command-line
script get command-line get executable get script get command-line get
] unit-test ] unit-test
{ "a" { "b" "c" } } [ { "factor" "a" { "b" "c" } } [
{ "-foo" "a" "b" "c" } parse-command-line { "factor" "-foo" "a" "b" "c" } parse-command-line
script get command-line get executable get script get command-line get
] unit-test ] unit-test

View File

@ -18,6 +18,7 @@ M: user-init-error error-file file>> ;
M: user-init-error error-line line#>> ; M: user-init-error error-line line#>> ;
M: user-init-error error-type drop +user-init-error+ ; M: user-init-error error-type drop +user-init-error+ ;
SYMBOL: executable
SYMBOL: script SYMBOL: script
SYMBOL: command-line SYMBOL: command-line
@ -76,6 +77,7 @@ SYMBOL: command-line
: parse-command-line ( args -- ) : parse-command-line ( args -- )
command-line off command-line off
script off script off
unclip executable set
(parse-command-line) ; (parse-command-line) ;
SYMBOL: main-vocab-hook SYMBOL: main-vocab-hook

View File

@ -28,7 +28,7 @@ from within Factor for more information.
os windows? [ script get "/?" = ] [ f ] if or ; os windows? [ script get "/?" = ] [ f ] if or ;
: command-line-startup ( -- ) : command-line-startup ( -- )
(command-line) rest parse-command-line (command-line) parse-command-line
help? [ cli-usage ] [ help? [ cli-usage ] [
load-vocab-roots load-vocab-roots
run-user-init run-user-init

View File

@ -32,8 +32,11 @@ IN: tools.deploy.shaker
! This file is some hairy shit. ! This file is some hairy shit.
: add-command-line-hook ( -- ) : add-command-line-hook ( -- )
[ (command-line) rest command-line set-global ] "command-line" [
startup-hooks get set-at ; (command-line) unclip
executable set-global
command-line set-global
] "command-line" startup-hooks get set-at ;
: strip-startup-hooks ( -- ) : strip-startup-hooks ( -- )
"Stripping startup hooks" show "Stripping startup hooks" show