Module Async_extra.Command

Async.Command is Core.Command with additional Async functions.

include module type of Core.Command with type Command.t = Core.Command.t with module Command.Spec = Core.Command.Spec
module Arg_type : sig ... end
module Flag : sig ... end
module Anons : sig ... end
module Param : sig ... end
module Let_syntax : sig ... end
module Spec : sig ... end
type ('main, 'result) basic_spec_command = summary:string ‑> ?⁠readme:(unit ‑> string) ‑> ('main, unit ‑> 'resultSpec.t ‑> 'main ‑> t
val basic_spec : ('main, unit) basic_spec_command
type 'result basic_command = summary:string ‑> ?⁠readme:(unit ‑> string) ‑> (unit ‑> 'result) Param.t ‑> t
val basic : unit basic_command
val group : summary:string ‑> ?⁠readme:(unit ‑> string) ‑> ?⁠preserve_subcommand_order:unit ‑> ?⁠body:(path:string list ‑> unit) ‑> (string * t) list ‑> t
val lazy_group : summary:string ‑> ?⁠readme:(unit ‑> string) ‑> ?⁠preserve_subcommand_order:unit ‑> ?⁠body:(path:string list ‑> unit) ‑> (string * t) list Core__.Import.Lazy.t ‑> t
val exec : summary:string ‑> ?⁠readme:(unit ‑> string) ‑> ?⁠child_subcommand:string list ‑> path_to_exe:[ `Absolute of string | `Relative_to_argv0 of string | `Relative_to_me of string ] ‑> unit ‑> t
val of_lazy : t Core__.Import.Lazy.t ‑> t
val summary : t ‑> string
module Shape : sig ... end
val shape : t ‑> Shape.t
val run : ?⁠version:string ‑> ?⁠build_info:string ‑> ?⁠argv:string list ‑> ?⁠extend:(string list ‑> string list) ‑> t ‑> unit
module Deprecated : sig ... end
type 'a with_options = ?⁠extract_exn:bool ‑> 'a
val async : unit Async_extra__.Import.Deferred.t basic_command with_options

async is like Core.Command.basic, except that the main function it expects returns unit Deferred.t, instead of unit. async will also start the Async scheduler before main is run, and will stop the scheduler when main returns.

async also handles top-level exceptions by wrapping the user-supplied function in a Monitor.try_with. If an exception is raised, it will print it to stderr and call shutdown 1. The extract_exn argument is passed along to Monitor.try_with; by default it is false.

val async_spec : ('a, unit Async_extra__.Import.Deferred.tbasic_spec_command with_options
val async_or_error : unit Async_extra__.Import.Deferred.Or_error.t basic_command with_options

async_or_error is like async, 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.

val async_spec_or_error : ('a, unit Async_extra__.Import.Deferred.Or_error.tbasic_spec_command with_options

staged functions allow the main function to be separated into two stages. The first part is guaranteed to run before the async scheduler is started, and the second part will run after the async scheduler is started. This is useful if the main function runs code that relies on the fact that threads have not been created yet (e.g. Daemon.daemonize).

As an example:

      let main () =
        assert (not (Scheduler.is_running ()));
        stage (fun `Scheduler_started ->
          assert (Scheduler.is_running ());
          Deferred.unit
        )
type 'r staged = ([ `Scheduler_started ] ‑> 'r) Core.Staged.t
module Staged : sig ... end

To create an Arg_type.t that uses auto-completion and uses Async to compute the possible completions, one should use

      Arg_type.create ~complete of_string

where complete wraps its Async operations in Thread_safe.block_on_async. With this, the complete function is only called when the executable is auto-completing, not for ordinary execution. This improves performance, and also means that the Async scheduler isn't started for ordinary execution of the command, which makes it possible for the command to daemonize (which requires the scheduler to not have been started).