ARTICLE: "command-line" "Command line arguments"
"Factor command line usage:"
{ $code "factor [options] [script] [arguments]" }
-"Zero or more options can be passed in, followed by an optional script file name. If the script file is specified, it will be run on startup using " { $link run-script } ". Any arguments after the script file are stored in the following variable, with no further processing by Factor itself:"
+"Zero or more options 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 }
"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>" }
"There is a way to override the default vocabulary to run on startup, if no script name or " { $snippet "-run" } " switch is specified:"
{ $subsections main-vocab-hook } ;
-HELP: run-script
-{ $values { "file" "a pathname string" } }
-{ $description "Parses the Factor source code stored in a file and runs it. The initial vocabulary search path is used. If the source file contains a " { $link POSTPONE: MAIN: } " declaration, the main entry point of the file will be also be executed. Loading messages will be suppressed." }
-{ $errors "Throws an error if loading the file fails, there input is malformed, or if a runtime error occurs while calling the parsed quotation or executing the main entry point." } ;
-
ABOUT: "command-line"
! Copyright (C) 2003, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.strings assocs combinators.smart
-continuations io io.encodings.utf8 io.files kernel
-kernel.private namespaces parser parser.notes prettyprint
-sequences source-files source-files.errors splitting system
+USING: accessors alien.strings assocs continuations
+io.encodings.utf8 io.files kernel kernel.private namespaces
+parser sequences source-files.errors splitting system
vocabs.loader ;
IN: command-line
: param ( param -- )
"=" split1 [ var-param ] [ bool-param ] if* ;
-: run-script ( file -- )
- t parser-quiet? [
- [
- parse-file [
- output>array
- [ nl "--- Data stack:" print stack. ] unless-empty
- ] call( quot -- )
- ]
- [ path>source-file main>> [ execute( -- ) ] when* ] bi
- ] with-variable ;
-
: (parse-command-line) ( args -- )
[
unclip "-" ?head [
! Copyright (C) 2011 Joe Groff.
! See http://factorcode.org/license.txt for BSD license.
-USING: combinators command-line eval io io.pathnames kernel
-layouts math math.parser namespaces parser system vocabs.loader
-;
+USING: accessors combinators combinators.smart command-line eval
+io io.pathnames kernel layouts math math.parser namespaces
+parser parser.notes prettyprint sequences source-files system
+vocabs.loader ;
IN: command-line.startup
: help? ( -- ? )
: version? ( -- ? ) "version" get ;
+: run-script ( file -- )
+ t parser-quiet? [
+ [
+ parse-file [
+ output>array
+ [ nl "--- Data stack:" print stack. ] unless-empty
+ ] call( quot -- )
+ ]
+ [ path>source-file main>> [ execute( -- ) ] when* ] bi
+ ] with-variable ;
+
: command-line-startup ( -- )
(command-line) parse-command-line {
{ [ help? ] [ help. ] }