include module type of Async.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
val basic : ('main, unit) basic_command
val basic' : unit basic_command'
val exec : summary:string ‑> ?readme:(unit ‑> string) ‑> path_to_exe:[ `Absolute 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 run : ?version:string ‑> ?build_info:string ‑> ?argv:string list ‑> ?extend:(string list ‑> string list) ‑> t ‑> unit
module Deprecated : sig ... end
val async : ('a, 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' : unit Async_extra.Import.Deferred.t basic_command' with_options
val async_basic : ('a, unit Async_extra.Import.Deferred.t) basic_command with_options
async_basic
is a deprecated synonym for async
that will eventually go away. It is
here to give code outside jane street a chance to switch over before we delete it.
val async_or_error : ('a, 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_or_error' : unit Async_extra.Import.Deferred.Or_error.t basic_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
)
module Staged = Async_extra.Command.Staged
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).
val rpc : summary:string ‑> ?readme:(unit ‑> string) ‑> ('main, Async.Rpc.Connection.t ‑> unit Async.Deferred.t) Spec.t ‑> 'main ‑> t
val config_or_rpc : summary:string ‑> ?readme:(unit ‑> string) ‑> ('main, [ `Config of Async_smtp.Std.Smtp_server.Config.t | `Rpc of Async.Rpc.Connection.t ] ‑> unit Async.Deferred.t) Spec.t ‑> 'main ‑> t