Module CommandSource

Sourcemodule type Enumerable_sexpable = sig ... end
Sourcemodule type Enumerable_stringable = sig ... end
Sourcemodule Auto_complete : sig ... end

Specifications for command-line auto-completion.

Sourcemodule Arg_type : sig ... end

Argument types.

Sourcemodule Flag : sig ... end

Command-line flag specifications.

Sourcemodule Anons : sig ... end

Anonymous command-line argument specification.

Sourcemodule Param : sig ... end

Command-line parameter specification.

Sourcemodule Let_syntax : sig ... end
Sourcemodule Spec : sig ... end

The old interface for command-line specifications -- Do Not Use.

Sourcetype t

Commands which can be combined into a hierarchy of subcommands.

Sourcetype ('main, 'result) basic_spec_command = summary:Base.string -> ?readme:(Base.unit -> Base.string) -> ('main, Base.unit -> 'result) Spec.t -> 'main -> t
Sourceval basic_spec : ('main, Base.unit) basic_spec_command

basic_spec ~summary ?readme spec main is a basic command that executes a function main which is passed parameters parsed from the command line according to spec. summary is to contain a short one-line description of its behavior. readme is to contain any longer description of its behavior that will go on that command's help screen.

Sourcetype 'result basic_command = summary:Base.string -> ?readme:(Base.unit -> Base.string) -> (Base.unit -> 'result) Param.t -> t

Same general behavior as basic_spec, but takes a command line specification built up using Params instead of Spec.

basic_or_error is like basic, except that the main function it expects may return an error, in which case it prints out the error message and shuts down with exit code 1.

Sourceval group : summary:Base.string -> ?readme:(Base.unit -> Base.string) -> ?preserve_subcommand_order:Base.unit -> ?body:(path:Base.string Base.list -> Base.unit) -> (Base.string * t) Base.list -> t

group ~summary subcommand_alist is a compound command with named subcommands, as found in subcommand_alist. summary is to contain a short one-line description of the command group. readme is to contain any longer description of its behavior that will go on that command's help screen.

NOTE: subcommand names containing underscores will be rejected; use dashes instead.

body is called when no additional arguments are passed -- in particular, when no subcommand is passed. Its path argument is the subcommand path by which the group command was reached.

Sourceval lazy_group : summary:Base.string -> ?readme:(Base.unit -> Base.string) -> ?preserve_subcommand_order:Base.unit -> ?body:(path:Base.string Base.list -> Base.unit) -> (Base.string * t) Base.list Base.Lazy.t -> t

lazy_group is the same as group, except that the list of subcommands may be generated lazily.

Sourceval exec : summary:Base.string -> ?readme:(Base.unit -> Base.string) -> ?child_subcommand:Base.string Base.list -> ?env: [ `Replace of (Base.string * Base.string) Base.list | `Extend of (Base.string * Base.string) Base.list | `Override of (Base.string * Base.string Base.option) Base.list | `Replace_raw of Base.string Base.list ] -> path_to_exe: [ `Absolute of Base.string | `Relative_to_argv0 of Base.string | `Relative_to_me of Base.string ] -> Base.unit -> t

exec ~summary ~path_to_exe runs exec on the executable at path_to_exe. If path_to_exe is `Absolute path then path is executed without any further qualification. If it is `Relative_to_me path then Filename.dirname Sys.executable_name ^ "/" ^ path is executed instead. All of the usual caveats about Sys.executable_name apply: specifically, it may only return an absolute path in Linux. On other operating systems it will return Sys.argv.(0). If it is `Relative_to_argv0 path then Sys.argv.(0) ^ "/" ^ path is executed.

The child_subcommand argument allows referencing a subcommand one or more levels below the top-level of the child executable. It should not be used to pass flags or anonymous arguments to the child.

Care has been taken to support nesting multiple executables built with Command. In particular, recursive help and autocompletion should work as expected.

NOTE: Non-Command executables can be used with this function but will still be executed when help -recursive is called or autocompletion is attempted (despite the fact that neither will be particularly helpful in this case). This means that if you have a shell script called "reboot-everything.sh" that takes no arguments and reboots everything no matter how it is called, you shouldn't use it with exec.

Additionally, no loop detection is attempted, so if you nest an executable within itself, help -recursive and autocompletion will hang forever (although actually running the subcommand will work).

Sourceval of_lazy : t Base.Lazy.t -> t

of_lazy thunk constructs a lazy command that is forced only when necessary to run it or extract its shape.

Sourceval summary : t -> Base.string

Extracts the summary string for a command.

Sourcemodule Shape : sig ... end

A Command_shape allows limited introspection of a Command, including subcommands, arguments, and doc strings. Think of it as machine-readable help.

Sourceval exit : Base.int -> _

call this instead of Core.exit if in command-related code that you want to run in tests. For example, in the body of Command.Param.no_arg_abort

Sourcemodule For_telemetry : sig ... end
Sourcemodule Deprecated : sig ... end

Deprecated should be used only by Deprecated_command. At some point it will go away.

Deprecated values that moved from Core.Command to Command_unix.

Sourceval run : [ `Use_Command_unix ]
  • deprecated [since 2021-03] Use [Command_unix]
Sourcemodule Path : sig ... end
Sourceval shape : [ `Use_Command_unix ]
  • deprecated [since 2021-03] Use [Command_unix]