]> gitweb.factorcode.org Git - factor.git/blob - basis/command-line/command-line.factor
change add-init-hook to add-startup-hook, new add-shutdown-hook word
[factor.git] / basis / command-line / command-line.factor
1 ! Copyright (C) 2003, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: init continuations hashtables io io.encodings.utf8
4 io.files io.pathnames kernel kernel.private namespaces parser
5 sequences strings system splitting vocabs.loader alien.strings ;
6 IN: command-line
7
8 SYMBOL: script
9 SYMBOL: command-line
10
11 : (command-line) ( -- args ) 10 getenv sift [ alien>native-string ] map ;
12
13 : rc-path ( name -- path )
14     os windows? [ "." prepend ] unless
15     home prepend-path ;
16
17 : run-bootstrap-init ( -- )
18     "user-init" get [
19         "factor-boot-rc" rc-path ?run-file
20     ] when ;
21
22 : run-user-init ( -- )
23     "user-init" get [
24         "factor-rc" rc-path ?run-file
25     ] when ;
26
27 : load-vocab-roots ( -- )
28     "user-init" get [
29         "factor-roots" rc-path dup exists? [
30             utf8 file-lines [ add-vocab-root ] each
31         ] [ drop ] if
32     ] when ;
33
34 : var-param ( name value -- ) swap set-global ;
35
36 : bool-param ( name -- ) "no-" ?head not var-param ;
37
38 : param ( param -- )
39     "=" split1 [ var-param ] [ bool-param ] if* ;
40
41 : run-script ( file -- )
42     t "quiet" set-global run-file ;
43
44 : parse-command-line ( args -- )
45     [ command-line off script off ] [
46         unclip "-" ?head
47         [ param parse-command-line ]
48         [ script set command-line set ] if
49     ] if-empty ;
50
51 SYMBOL: main-vocab-hook
52
53 : main-vocab ( -- vocab )
54     embedded? [
55         "alien.remote-control"
56     ] [
57         main-vocab-hook get [ call( -- vocab ) ] [ "listener" ] if*
58     ] if ;
59
60 : default-cli-args ( -- )
61     global [
62         "quiet" off
63         "e" off
64         "user-init" on
65         embedded? "quiet" set
66         main-vocab "run" set
67     ] bind ;
68
69 : ignore-cli-args? ( -- ? )
70     os macosx? "run" get "ui" = and ;
71
72 [ default-cli-args ] "command-line" add-startup-hook