From c0dda5c7e95e9d67e9436d4ec6526c7be95bd297 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Tue, 23 Dec 2014 08:12:31 -0800 Subject: [PATCH] command-line: save the executable in a variable so that people don't use (command-line) directly if possible. --- basis/bootstrap/finish-staging.factor | 2 +- basis/bootstrap/stage2.factor | 2 +- basis/command-line/command-line-docs.factor | 11 ++++-- basis/command-line/command-line-tests.factor | 36 ++++++++++---------- basis/command-line/command-line.factor | 2 ++ basis/command-line/startup/startup.factor | 2 +- basis/tools/deploy/shaker/shaker.factor | 7 ++-- 7 files changed, 37 insertions(+), 25 deletions(-) diff --git a/basis/bootstrap/finish-staging.factor b/basis/bootstrap/finish-staging.factor index 5dd6d4cd53..b4e8926aa8 100644 --- a/basis/bootstrap/finish-staging.factor +++ b/basis/bootstrap/finish-staging.factor @@ -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 diff --git a/basis/bootstrap/stage2.factor b/basis/bootstrap/stage2.factor index f74e577220..15872ce499 100644 --- a/basis/bootstrap/stage2.factor +++ b/basis/bootstrap/stage2.factor @@ -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 diff --git a/basis/command-line/command-line-docs.factor b/basis/command-line/command-line-docs.factor index fa6310a92d..66263afebf 100644 --- a/basis/command-line/command-line-docs.factor +++ b/basis/command-line/command-line-docs.factor @@ -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)." } ; diff --git a/basis/command-line/command-line-tests.factor b/basis/command-line/command-line-tests.factor index 01099ae19d..36943a2a58 100644 --- a/basis/command-line/command-line-tests.factor +++ b/basis/command-line/command-line-tests.factor @@ -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 diff --git a/basis/command-line/command-line.factor b/basis/command-line/command-line.factor index 37511dae90..7026abd19c 100644 --- a/basis/command-line/command-line.factor +++ b/basis/command-line/command-line.factor @@ -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 diff --git a/basis/command-line/startup/startup.factor b/basis/command-line/startup/startup.factor index a93bf2763f..2a77de3692 100644 --- a/basis/command-line/startup/startup.factor +++ b/basis/command-line/startup/startup.factor @@ -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 diff --git a/basis/tools/deploy/shaker/shaker.factor b/basis/tools/deploy/shaker/shaker.factor index b4eaffadbf..4610e2b547 100755 --- a/basis/tools/deploy/shaker/shaker.factor +++ b/basis/tools/deploy/shaker/shaker.factor @@ -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