module Cmd:sig
..end
Cmd
provides functions to execute non-build commands
and perform IO operations. They can be used to define the default
value of configuration keys in assemble files.
type'a
result =[ `Error of string | `Ok of 'a ]
val ret : 'a -> 'a result
ret v
is `Ok v
.val error : string -> 'a result
error e
is `Error e
.val bind : 'a result ->
('a -> 'b result) -> 'b result
bind r f
is f v
if r = `Ok v
and r
if r = `Error _
.val map : 'a result -> ('a -> 'b) -> 'b result
map r f
is bind r (fun v -> ret (f v))
.val get : 'a result -> 'a
get r
is v
if r = `Ok v
andInvalid_argument
otherwise.val on_error : ?level:Assemblage.Log.level -> use:'a -> 'a result -> 'a
on_error ~level ~use r
is:
v
if r = `Ok v
use
if r = `Error msg
. As a side effect msg
is
logged with level level
(defaults to
Log.Error
)val ignore_error : use:'a -> 'a result -> 'a
val reword_error : ?replace:bool ->
string -> 'a result -> 'a result
reword_error msg r
uses msg
for the error message in case of
`Error
. If replace is false
(default), msg
is stacked on
top of the old message.val exn_error : ?msg:(Printexc.raw_backtrace -> exn -> 'a -> string) ->
('a -> 'b) -> 'a -> 'b result
val (>>=) : 'a result ->
('a -> 'b result) -> 'b result
r >>= f
is bind r f
.val (>>|) : 'a result -> ('a -> 'b) -> 'b result
r >>| f
is map r f
.module Infix:sig
..end
typepath =
Assemblage.Path.t
module Path:sig
..end
module File:sig
..end
module Dir:sig
..end
module Vcs:sig
..end
val env : string -> string option
env var
is the value if the environment variable var
, if
defined.val get_env : string -> string result
val exists : string -> bool result
exists cmd
is true
if cmd
exists and can be invoked.val exec_ret : string -> string list -> int
exec_ret cmd args
executes cmd
with arguments args
and
returns the exit code of the invocation.val exec : string -> string list -> unit result
exec cmd args
executes cmd
with arguments args
. On exit
code 0
returns `Ok ()
. Otherwise an error message with
the failed invocation and its exit code is returned in `Error
.val read : ?trim:bool -> string -> string list -> string result
read cmd args
execute cmd
with arguments args
and returns
its standard output. If cmd
's return code is non zero returns
an error message. If trim
is true
(default) the contents is
passed to String.trim
before being returned.val read_lines : string -> string list -> string list result
input_lines cmd args
is like input ~trim:false cmd args
but
the input is splitted at '\n'
.val write : string -> string list -> path -> unit result
write cmd args file
execute cmd
with arguments args
and writes
the invocation's stdout
to file
. In cmd
's return code is non
zero returns an error message and file
is left intact.