]> gitweb.factorcode.org Git - factor.git/blob - core/cli.factor
more sql changes
[factor.git] / core / cli.factor
1 ! Copyright (C) 2003, 2006 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 IN: command-line
4 USING: errors hashtables io kernel kernel-internals namespaces
5 parser sequences strings ;
6
7 : ?run-file ( file -- )
8     dup exists? [ run-file ] [ drop ] if ;
9
10 : run-bootstrap-init ( -- )
11     "user-init" get [
12         home ".factor-boot-rc" path+ ?run-file
13     ] when ;
14
15 : run-user-init ( -- )
16     "user-init" get [
17         home ".factor-rc" path+ ?run-file
18     ] when ;
19
20 : cli-var-param ( name value -- ) swap set-global ;
21
22 : cli-bool-param ( name -- ) "no-" ?head not cli-var-param ;
23
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.
28     #!
29     #! Arguments containing = are handled differently; they
30     #! set the object path.
31     "=" split1 [ cli-var-param ] [ cli-bool-param ] if* ;
32
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 ;
38
39 : cli-args ( -- args ) 10 getenv ;
40
41 : default-shell "tty" ;
42
43 : default-cli-args
44     #! Some flags are *on* by default, unless user specifies
45     #! -no-<flag> CLI switch
46     "e" off
47     "user-init" on
48     "compile" on
49     "native-io" on
50     macosx? "cocoa" set
51     unix? macosx? not and "x11" set
52     default-shell "shell" set ;
53
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 ;
58
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* ;
63
64 IN: shells
65
66 : none ;