Module B0_cmdlet

Cmdlets.

Cmdlets are used to define custom software life-cycle procedures. Examples range from invoking linters on your sources to perform post build checks or actions.

See the cmdlet manual for a short introduction.

Cmdlets run in the same environment in which b0 is invoked (XXX lift that restriction ?).

Cmdlets

type t

The type for cmdlets.

module Env : sig ... end

Cmdlet execution environments.

The type for cmdlet implementations. A function that given an execution context and command line arguments for the cmdlet should eventually specify a way to exit.

val v : ?doc:string -> ?meta:B0_meta.t -> string -> cmd -> t

v n ~doc ~meta cmd is a cmdlet named n implemented by cmd with doc string doc and metadata meta.

val cmd : t -> cmd

cmd c is the command of the cmdlet.

Shortcuts

val exit_of_result : (unit, string) Stdlib.result -> B00_std.Os.Exit.t

exit_of_result v exits with B00_cli.Exit.ok if v is Ok () and logs the Error and exits with B00_cli.Exit.some_error if v is Error _.

val exit_of_result' : (B00_std.Os.Exit.t, string) Stdlib.result -> B00_std.Os.Exit.t

exit_of_result' v exits with if v is Ok e and logs the Error and exits with B00_cli.Exit.some_error if v is Error _.

val in_scope_dir : Env.t -> B00_std.Fpath.t -> B00_std.Fpath.t

in_scope_dir env p is Fpath.(Env.root_dir env // p)).

val in_root_dir : Env.t -> B00_std.Fpath.t -> B00_std.Fpath.t

in_scope_dir env p is Fpath.(Env.root_dir env // p)).

val in_scratch_dir : Env.t -> B00_std.Fpath.t -> B00_std.Fpath.t

in_scope_dir env p is Fpath.(Env.scratch_dir env // p)).

Script execution

exec_file exe e args executes the file exe with arguments cmd. The scope directory is used as the default cwd and to resolve relative exe paths.

exec_tool tool e args executes the tool exe with arguments cmd The scope directory is used as the default cwd. exe is looked up using B00_std.Os.Cmd.get_tool, if that fails the error is logged and we exit we and exits with B00_cli.Exit.some_error.

Command line interaction

Use B00_cli and B0_cli to parse cmdlet arguments and B00_cli.Exit for exit codes. Given a suitable Cmdliner term this function can be used to implement the cmdlet's command.

val eval : ?man_xrefs:Cmdliner.Manpage.xref list -> ?man:Cmdliner.Manpage.block list -> ?envs:Cmdliner.Term.env_info list -> ?exits:Cmdliner.Term.exit_info list -> ?sdocs:string -> ?docs:string -> ?doc:string -> ?version:string -> Env.t -> B00_std.Cmd.t -> B00_std.Os.Exit.t Cmdliner.Term.t -> B00_std.Os.Exit.t

eval e cmd t defines a cmdlet command by evaluating the cmdliner term t with arguments cmd. The menagerie of optional parameters define a Cmdliner.Term.info value for the term, see the docs there. By default doc is derived from the cmdlet's doc string and exits is B00_cli.Exit.infos.

B0 definition API

include B0_def.S with type t := t
val define : ?doc:string -> ?meta:B0_meta.t -> string -> B0_def.def
val def_kind : string
val def : t -> B0_def.def
val name : t -> string
val basename : t -> string
val doc : t -> string
val equal : t -> t -> bool
val compare : t -> t -> int
val meta : t -> B0_meta.t
val has_meta : 'a B0_meta.key -> t -> bool
val find_meta : 'a B0_meta.key -> t -> 'a option
val get_meta : 'a B0_meta.key -> t -> ('a, string) Stdlib.result
val add : t -> unit
val list : unit -> t list
val find : string -> t option
val get : string -> t
val get_or_suggest : string -> (tt list) Stdlib.result
val get_or_hint : string -> (t, string) Stdlib.result
val get_list_or_hint : ?empty_means_all:bool -> string list -> (t list, string) Stdlib.result
val pp_name_str : string B00_std.Fmt.t
val pp_name : t B00_std.Fmt.t
val pp_doc : t B00_std.Fmt.t
val pp_synopsis : t B00_std.Fmt.t
val pp : t B00_std.Fmt.t
module Set : sig ... end
module Map : sig ... end