package mirage

  1. Overview
  2. Docs

Command-line handling.

type 'a args = {
  1. context : 'a;
  2. config_file : Fpath.t;
  3. context_file : Fpath.t option;
  4. output : string option;
  5. dry_run : bool;
}

The type for global arguments.

val default_args : unit args
val peek_args : ?with_setup:bool -> mname:string -> string array -> unit args option

peek_args ?with_setup argv parses the global command-line arguments. If with_setup is set (by default it is), interprets -v and --color to set-up the terminal configuration as a side-effect. Returns None if global command-line arguments are invalid.

val peek_output : string array -> string option

peek_full_eval argv reads the --output option from argv; the return value is None if option is absent in argv.

val pp_args : 'a Fmt.t -> 'a args Fmt.t

pp_args is the pretty-printer for args.

Sub-commands

type 'a configure_args = {
  1. args : 'a args;
  2. depext : bool;
  3. extra_repo : (string * string) list;
}

The type for arguments of the configure sub-command.

type 'a build_args = 'a args

The type for arguments of the build sub-command.

type 'a clean_args = 'a args

The type for arguments of the clean sub-command.

type 'a help_args = 'a args

The type for arguments of the help sub-command.

type query_kind = [
  1. | `Name
  2. | `Packages
  3. | `Opam
  4. | `Files
  5. | `Dune of [ `Config | `Build | `Project | `Workspace | `Dist ]
  6. | `Makefile
]
val pp_query_kind : query_kind Fmt.t

pp_query_kind is the pretty-printer for query kinds.

type 'a query_args = {
  1. args : 'a args;
  2. kind : query_kind;
  3. depext : bool;
  4. extra_repo : (string * string) list;
}

The type for arguments of the query sub-command.

type 'a describe_args = {
  1. args : 'a args;
  2. dotcmd : string;
  3. dot : bool;
  4. eval : bool option;
}

The type for arguments of the describe sub-command.

val peek_full_eval : string array -> bool option

peek_full_eval argv reads the --eval option from argv; the return value is None if option is absent in argv.

type 'a action =
  1. | Configure of 'a configure_args
  2. | Query of 'a query_args
  3. | Describe of 'a describe_args
  4. | Clean of 'a clean_args
  5. | Help of 'a help_args

A value of type action is the result of parsing command-line arguments using parse_args.

val pp_action : 'a Fmt.t -> 'a action Fmt.t

pp_action is the pretty-printer for actions.

val args : 'a action -> 'a args

args a are a's global arguments.

Evalutation

val eval : ?with_setup:bool -> ?help_ppf:Format.formatter -> ?err_ppf:Format.formatter -> name:string -> version:string -> configure:'a Cmdliner.Term.t -> query:'a Cmdliner.Term.t -> describe:'a Cmdliner.Term.t -> clean:'a Cmdliner.Term.t -> help:'a Cmdliner.Term.t -> mname:string -> string array -> 'a action Cmdliner.Term.result

Parse the functoria command line. The arguments to ~configure, ~describe, etc., describe extra command-line arguments that should be accepted by the corresponding subcommands.

There are no side effects, save for the printing of usage messages and other help when either the 'help' subcommand or no subcommand is specified.

type 'a result = [
  1. | `Ok of 'a action
  2. | `Error of 'a args option * [ `Exn | `Parse | `Term ]
  3. | `Version
]

Similar to Cmdliner.Term.result but help is folded into `Ok and errors also carry global command-line parameters.

val peek : ?with_setup:bool -> mname:string -> string array -> unit result

peek is the same as eval but without failing on unknown arguments.

OCaml

Innovation. Community. Security.