Os.ExitSourceProgram exit.
There are two ways for a program to exit: either by returning an exit code or by calling B0_std.Os.Cmd.execv. The type here allows to represent these two ways of exiting.
The type for exit codes.
The type for execv calls.
The type for specifying program exits.
get_code e is the exit code of e. Raises Invalid_argument if e is Execv.
exit ~on_error e exits according to e:
e is Code c, Stdlib.exit c is called and the function never returns.e is Execv execv, execv is called. This can only return with an Error _. In that case the error is logged and exit is called again with on_error (and the default on_error)on_error defaults to some_error. Except if an asynchronous exception is raised this function never returns.
Note. The constants here match those established by Cmdliner with another one useful in cli tools. But we don't want a Cmdliner dependency on it here.
some_error is Code 123, it indicates an indiscriminate error reported on stdout.
internal_error is Code 125, it indicates an unexpected internal error (bug).
resultsof_result v exits with ok if v is Ok () and logs the Error and exits with some_error if v is Error _.
of_result v exits with e if v is Ok e and logs the error and exits with some_error if v is Error _.
execvexec ?env ?cwd ?argv0 cmd is an Exec _. That has a call to Os.Cmd.execv with the corresponding arguments.
execv_env exec is the environment of exec.
on_sigint ~hook f calls f () and returns its value. If SIGINT is signalled during that time hook is called followed by exit 130 – that is the exit code a SIGINT would produce.
on_sigint replaces an existing signal handler for Sys.sigint during time of the function call. It is restored when the function returns.
Note. Since Stdlib.exit is called Stdlib.at_exit functions are called if a SIGINT occurs during the call to f. This is not the case on an unhandled SIGINT.