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
do-startup-hooks
(command-line) rest parse-command-line
(command-line) parse-command-line
"run" get run
output-stream get [ stream-flush ] when*
0 exit

View File

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

View File

@ -23,10 +23,17 @@ $nl
HELP: (command-line)
{ $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
{ $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
{ $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 ;
IN: command-line
{ f { "a" "b" "c" } } [
{ "-run=test-voc" "a" "b" "c" } parse-command-line
script get command-line get
{ "factor" f { "a" "b" "c" } } [
{ "factor" "-run=test-voc" "a" "b" "c" } parse-command-line
executable get script get command-line get
] unit-test
{ f { "-a" "b" "c" } } [
{ "-run=test-voc" "-a" "b" "c" } parse-command-line
script get command-line get
{ "factor" f { "-a" "b" "c" } } [
{ "factor" "-run=test-voc" "-a" "b" "c" } parse-command-line
executable get script get command-line get
] unit-test
{ f { "a" "-b" "c" } } [
{ "-run=test-voc" "a" "-b" "c" } parse-command-line
script get command-line get
{ "factor" f { "a" "-b" "c" } } [
{ "factor" "-run=test-voc" "a" "-b" "c" } parse-command-line
executable get script get command-line get
] unit-test
{ f { "a" "b" "-c" } } [
{ "-run=test-voc" "a" "b" "-c" } parse-command-line
script get command-line get
{ "factor" f { "a" "b" "-c" } } [
{ "factor" "-run=test-voc" "a" "b" "-c" } parse-command-line
executable get script get command-line get
] unit-test
{ "a" { "b" "c" } } [
{ "a" "b" "c" } parse-command-line
script get command-line get
{ "factor" "a" { "b" "c" } } [
{ "factor" "a" "b" "c" } parse-command-line
executable get script get command-line get
] unit-test
{ "a" { "b" "c" } } [
{ "-foo" "a" "b" "c" } parse-command-line
script get command-line get
{ "factor" "a" { "b" "c" } } [
{ "factor" "-foo" "a" "b" "c" } parse-command-line
executable get script get command-line get
] 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-type drop +user-init-error+ ;
SYMBOL: executable
SYMBOL: script
SYMBOL: command-line
@ -76,6 +77,7 @@ SYMBOL: command-line
: parse-command-line ( args -- )
command-line off
script off
unclip executable set
(parse-command-line) ;
SYMBOL: main-vocab-hook

View File

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

View File

@ -32,8 +32,11 @@ IN: tools.deploy.shaker
! This file is some hairy shit.
: 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 ( -- )
"Stripping startup hooks" show