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