Allow access to command line arguments in deployed apps

db4
Slava Pestov 2009-10-02 21:00:12 -05:00
parent cfc8b06ac0
commit 21eea4d88c
5 changed files with 31 additions and 10 deletions

View File

@ -25,7 +25,7 @@ HELP: (command-line)
{ $description "Outputs the command line parameters which were passed to the Factor VM on startup." } ; { $description "Outputs the command line parameters which were passed to the Factor VM on startup." } ;
HELP: command-line HELP: command-line
{ $var-description "The command line parameters which follow the name of the script on the 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 } "." } ;
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)." } ;
@ -139,8 +139,8 @@ $nl
ARTICLE: "cli" "Command line arguments" ARTICLE: "cli" "Command line arguments"
"Factor command line usage:" "Factor command line usage:"
{ $code "factor [system switches...] [script args...]" } { $code "factor [VM args...] [script] [args...]" }
"Zero or more system switches can be passed in, followed by an optional script file name. If the script file is specified, it will be run on startup, any arguments after the script file are stored in a variable, with no further processing by Factor itself:" "Zero or more VM arguments can be passed in, followed by an optional script file name. If the script file is specified, it will be run on startup, any arguments after the script file are stored in the following variable, with no further processing by Factor itself:"
{ $subsections command-line } { $subsections command-line }
"Instead of running a script, it is also possible to run a vocabulary; this invokes the vocabulary's " { $link POSTPONE: MAIN: } " word:" "Instead of running a script, it is also possible to run a vocabulary; this invokes the vocabulary's " { $link POSTPONE: MAIN: } " word:"
{ $code "factor [system switches...] -run=<vocab name>" } { $code "factor [system switches...] -run=<vocab name>" }

View File

@ -106,3 +106,10 @@ os windows? os macosx? or [
os macosx? [ os macosx? [
[ ] [ "tools.deploy.test.14" shake-and-bake run-temp-image ] unit-test [ ] [ "tools.deploy.test.14" shake-and-bake run-temp-image ] unit-test
] when ] when
[ { "a" "b" "c" } ] [
"tools.deploy.test.15" shake-and-bake deploy-test-command
{ "a" "b" "c" } append
ascii [ lines ] with-process-reader
rest
] unit-test

View File

@ -7,9 +7,8 @@ words memory kernel.private continuations io vocabs.loader
system strings sets vectors quotations byte-arrays sorting system strings sets vectors quotations byte-arrays sorting
compiler.units definitions generic generic.standard compiler.units definitions generic generic.standard
generic.single tools.deploy.config combinators classes generic.single tools.deploy.config combinators classes
classes.builtin slots.private grouping ; classes.builtin slots.private grouping command-line ;
QUALIFIED: bootstrap.stage2 QUALIFIED: bootstrap.stage2
QUALIFIED: command-line
QUALIFIED: compiler.errors QUALIFIED: compiler.errors
QUALIFIED: continuations QUALIFIED: continuations
QUALIFIED: definitions QUALIFIED: definitions
@ -22,11 +21,14 @@ IN: tools.deploy.shaker
! This file is some hairy shit. ! This file is some hairy shit.
: add-command-line-hook ( -- )
[ (command-line) command-line set-global ] "command-line"
init-hooks get set-at ;
: strip-init-hooks ( -- ) : strip-init-hooks ( -- )
"Stripping startup hooks" show "Stripping startup hooks" show
{ {
"alien.strings" "alien.strings"
"command-line"
"cpu.x86" "cpu.x86"
"destructors" "destructors"
"environment" "environment"
@ -328,7 +330,7 @@ IN: tools.deploy.shaker
classes-intersect-cache classes-intersect-cache
implementors-map implementors-map
update-map update-map
command-line:main-vocab-hook main-vocab-hook
compiled-crossref compiled-crossref
compiled-generic-crossref compiled-generic-crossref
compiler-impl compiler-impl
@ -503,6 +505,7 @@ SYMBOL: deploy-vocab
strip-debugger strip-debugger
compute-next-methods compute-next-methods
strip-init-hooks strip-init-hooks
add-command-line-hook
strip-c-io strip-c-io
strip-default-methods strip-default-methods
strip-compiler-classes strip-compiler-classes

View File

@ -0,0 +1,8 @@
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: command-line io namespaces sequences ;
IN: tools.deploy.test.15
: main ( -- ) command-line get [ print ] each ;
MAIN: main

View File

@ -19,7 +19,10 @@ IN: tools.deploy.test
] bi* ] bi*
<= ; <= ;
: run-temp-image ( -- ) : deploy-test-command ( -- args )
os macosx? os macosx?
"resource:Factor.app/Contents/MacOS/factor" normalize-path vm ? "resource:Factor.app/Contents/MacOS/factor" normalize-path vm ?
"-i=" "test.image" temp-file append 2array try-output-process ; "-i=" "test.image" temp-file append 2array ;
: run-temp-image ( -- )
deploy-test-command try-output-process ;