Fossil SCM

fossil-scm / www / th1_argv.wiki

TH1 "argv" API

The "argv" API provides features for accessing command-line arguments and GET/POST values. They (unfortunately) do not provide access to POST data submitted in JSON mode (which fossil internally doesn't really know about).

Example usage:

<th1>
set argc [argv len]
set appName [argv at 0]
  1. Fetch --foo|-f argument:
set foo [argv getstr foo f "default value"] <th1>

(Note that fossil does not actually care if an argument starts with 1 or 2 dashes. The convention of using 1 for "short-form" flags and 2 for "long-form" is purely historical.)

The various subcommands are described below...

len

Returns the number of arguments.

set argc [argv len]

at

Fetches the argument at the given index (0-based).

set arg [argv at 3]

The fossil binary's name is stored in argument #0.

getstr|string

Searches for a CLI/GET/POST parameter. In CLI this function has some non-intuitive behaviour inherited from fossil's internals: once a flag/parameter is fetched, it is removed from the internal arguments list, meaning that this function will never see it a second time.

set something [argv string "something" "S" "default"]

If no default value is provided, an error is triggered if the value is not found.

If you do not want to search for a short-form flag, set it to an empty string.

NOTE: flag checking does not work in CGI mode when using upper-case flags (fossil treats upper-case names as environment variables).

getbool|bool

Works almost like getstr but searches for boolean flags. CLI boolean flags have no explicit value, and are "true" if the are set at all.

set doSomething [argv bool "do-something" "D" 0]

getint|int

Works almost like getstr but searches for integer flags.

set limit [argv int "limit" "L" 10]

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button