1 ! Copyright (C) 2003, 2006 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
4 USING: errors hashtables io kernel kernel-internals namespaces
5 parser sequences strings ;
7 : ?run-file ( file -- )
8 dup exists? [ run-file ] [ drop ] if ;
10 : run-bootstrap-init ( -- )
12 home ".factor-boot-rc" path+ ?run-file
15 : run-user-init ( -- )
17 home ".factor-rc" path+ ?run-file
20 : cli-var-param ( name value -- ) swap set-global ;
22 : cli-bool-param ( name -- ) "no-" ?head not cli-var-param ;
24 : cli-param ( param -- )
25 #! Handle a command-line argument starting with '-' by
26 #! setting that variable to t, or if the argument is
27 #! prefixed with 'no-', setting the variable to f.
29 #! Arguments containing = are handled differently; they
30 #! set the object path.
31 "=" split1 [ cli-var-param ] [ cli-bool-param ] if* ;
33 : cli-arg ( argument -- argument )
34 #! Handle a command-line argument. If the argument was
35 #! consumed, returns f. Otherwise returns the argument.
36 #! Parameters that start with + are runtime parameters.
37 "-" ?head [ cli-param f ] when ;
39 : cli-args ( -- args ) 10 getenv ;
41 : default-shell "tty" ;
44 #! Some flags are *on* by default, unless user specifies
45 #! -no-<flag> CLI switch
51 unix? macosx? not and "x11" set
52 default-shell "shell" set ;
54 : ignore-cli-args? ( -- ? )
55 #! On Mac OS X, files to run are given to us via a Cocoa API
56 #! so we ignore any command line switches which name files.
57 macosx? "shell" get "ui" = and ;
59 : parse-command-line ( -- )
60 cli-args [ cli-arg ] subset
61 ignore-cli-args? [ drop ] [ [ run-file ] each ] if
62 "e" get [ eval flush ] when* ;