|
1
|
<h1>TH1 "argv" API</h1> |
|
2
|
|
|
3
|
The "argv" API provides features for accessing command-line arguments |
|
4
|
and GET/POST values. They (unfortunately) do not provide access to |
|
5
|
POST data submitted in JSON mode (which fossil internally doesn't really |
|
6
|
know about). |
|
7
|
|
|
8
|
Example usage: |
|
9
|
|
|
10
|
<nowiki><pre> |
|
11
|
<th1> |
|
12
|
set argc [argv len] |
|
13
|
set appName [argv at 0] |
|
14
|
# Fetch --foo|-f argument: |
|
15
|
set foo [argv getstr foo f "default value"] |
|
16
|
<th1> |
|
17
|
</pre></nowiki> |
|
18
|
|
|
19
|
(Note that fossil does not actually care if an argument starts |
|
20
|
with 1 or 2 dashes. The convention of using 1 for "short-form" |
|
21
|
flags and 2 for "long-form" is purely historical.) |
|
22
|
|
|
23
|
The various subcommands are described below... |
|
24
|
|
|
25
|
<h2>len</h2> |
|
26
|
|
|
27
|
Returns the number of arguments. |
|
28
|
|
|
29
|
<nowiki><pre> |
|
30
|
set argc [argv len] |
|
31
|
</pre></nowiki> |
|
32
|
|
|
33
|
|
|
34
|
<h2>at</h2> |
|
35
|
|
|
36
|
Fetches the argument at the given index (0-based). |
|
37
|
|
|
38
|
<nowiki><pre> |
|
39
|
set arg [argv at 3] |
|
40
|
</pre></nowiki> |
|
41
|
|
|
42
|
The fossil binary's name is stored in argument #0. |
|
43
|
|
|
44
|
<h2>getstr|string</h2> |
|
45
|
|
|
46
|
Searches for a CLI/GET/POST parameter. In CLI this function has some |
|
47
|
non-intuitive behaviour inherited from fossil's internals: once a |
|
48
|
flag/parameter is fetched, it is removed from the internal arguments |
|
49
|
list, meaning that this function will never see it a second time. |
|
50
|
|
|
51
|
<nowiki><pre> |
|
52
|
set something [argv string "something" "S" "default"] |
|
53
|
</pre></nowiki> |
|
54
|
|
|
55
|
If no default value is provided, an error is triggered if the value is |
|
56
|
not found. |
|
57
|
|
|
58
|
If you do not want to search for a short-form flag, set it to an empty |
|
59
|
string. |
|
60
|
|
|
61
|
NOTE: flag checking does not work in CGI mode when using <em>upper-case</em> |
|
62
|
flags (fossil treats upper-case names as environment variables). |
|
63
|
|
|
64
|
<h2>getbool|bool</h2> |
|
65
|
|
|
66
|
Works almost like <tt>getstr</tt> but searches for boolean flags. CLI boolean flags |
|
67
|
have no explicit value, and are "true" if the are set at all. |
|
68
|
|
|
69
|
<nowiki><pre> |
|
70
|
set doSomething [argv bool "do-something" "D" 0] |
|
71
|
</pre></nowiki> |
|
72
|
|
|
73
|
<h2>getint|int</h2> |
|
74
|
|
|
75
|
Works almost like <tt>getstr</tt> but searches for integer flags. |
|
76
|
|
|
77
|
|
|
78
|
<nowiki><pre> |
|
79
|
set limit [argv int "limit" "L" 10] |
|
80
|
</pre></nowiki> |
|
81
|
|