parameter t name declares a configuration parameter.
This declaration extends the common-options grammar by adding the following rules
common-options =
...
| common-options, R | R, common-options
R = ["--<plugin>-<name>", ["="], t],
where <plugin> is the name of the plugin in which the configuration parameter is specified. (Note, the name of a plugin is the name of the file in which it is packed without the extension, e.g., a plugin foo.plugin has name foo).
When the --<plugin>-<name> v is specified on the command line, or a configuration file, or in the environment, then get ctxt p will evaluate to v, where p is the declared parameter.
The as_flag option makes the value part optional on the command line, so that declare ~as_flag=v t name extends the grammar by adding the following rules
common-options =
...
| common-options, R | R, common-options
R = ["--<plugin>-<name>", [["="], t]],
Then, if the parameter was specified on the command line without an argument, then v will be used as the value of the parameter.
When aliases are specified, then for each name in the aliases a --<plugin>-<name> option will be added.
Note, even if the name is short (i.e., consisting only of one letter) it will still be prefixed with the plugin name and interpreted as a long option, e.g., if name is "k" and the plugin name is "foo", then the option name will be "--foo-k".
Examples
Declaring a simple configuration parameter:
open Core_kernel[@@warning "-D"]
open Bap_main.Extension
let depth = Configuration.parameter Type.int "depth"
let () =
Bap_main.Extension.declare @@ fun ctxt ->
printf "Will dive to depth %d\n"
(Configuration.get ctxt depth)
The Extension.Syntax module adds an infix (-->) operator for the get function. Using this operator the previous example could be rewritten as:
open Core_kernel[@@warning "-D"]
open Bap_main.Extension
open Bap_main.Extension.Syntax
let depth = Configuration.parameter Type.int "depth"
let () =
Bap_main.Extension.declare @@ fun ctxt ->
printf "Will dive to depth %d\n" (ctxt-->depth)