package climate

  1. Overview
  2. Docs
type 'a t
val singleton : ?desc:string -> 'a Arg_parser.t -> 'a t

Declare a single command. Performs some checks that the parser is well-formed and raises a Spec_error.E if iat's invalid.

type 'a subcommand
val subcommand : ?hidden:bool -> string -> 'a t -> 'a subcommand
val group : ?default_arg_parser:'a Arg_parser.t -> ?desc:string -> 'a subcommand list -> 'a t

group children returns a command with a hierarchy of subcommands, the leaves of which will be either singletons or empty groups (groups with an empty list of children). If the default_arg_parser argument is passed then sequences of subcommands may terminating with this command and will be passed with that argument. Performs some checks that each parser is well-formed and raises a Spec_error.E if an invalid parser is found.

val print_completion_script_bash : _ t

A command that has the side effect of printing the completion script of the entire command it's contained inside. It's safe to bury this inside a hidden command group of internal commands. The command takes some arguments to configure the generated completion script, similar to the arguments of the function completion_script_bash.

val completion_script_bash : ?eval_config:Eval_config.t -> ?program_exe_for_reentrant_query:[ `Program_name | `Other of string ] -> ?global_symbol_prefix:[ `Random | `Custom of string ] -> ?command_hash_in_function_names:bool -> ?program_name:Program_name.t -> ?options:Climate__.Completion.Options.t -> _ t -> string

Returns a bash script that can be sourced in a shell to register completions for the command.

program_name will be the name which the completion script is registered under in the shell, and should be the main way users will call the program. Usually this should be the name of the executable that will be installed in the user's PATH.

program_exe_for_reentrant_query determines how the completion script will call back into the program when resolving a reentrant query. Pass `Program_name (the default) to have the completion script run the value of the program_name argument. In order to experiment with completion scripts during development, pass `Other "path/to/exe" instead, to allow the completion script to find the development executable. For example one might pass `Other "_build/default/bin/foo.exe" if building with dune.

global_symbol_prefix determines the prefix of global symbols in the generated script

command_hash_in_function_names determines if function names are augmented with a hash of the subcommand path and argument (if applicable) for which the generated function computes completion suggestions. This helps to avoid cases where multiple functions are generated with the same names due to the names of subcommands to the program colliding with mangled names of generated functions. This should be rare in practice but to be safe this defaults to true.

val eval : ?eval_config:Eval_config.t -> ?program_name:Program_name.t -> 'a t -> string list -> 'a

Run the command on given arguments. Raises a Parse_error.E if the command line is invalid. By default the program name will be taken from Sys.argv.(0) but this can be overriden via the program_name argument.

val run : ?eval_config:Eval_config.t -> 'a t -> 'a

Run the command line parser returning its result. Parse errors are handled by printing an error message to stderr and exiting.

val run_singleton : ?eval_config:Eval_config.t -> ?desc:string -> 'a Arg_parser.t -> 'a

run_singleton arg_parser is a shorthand for run (singleton arg_parser)

OCaml

Innovation. Community. Security.