Module Assemblage.Cmd

module Cmd: sig .. end
Executing non-build commands and IO operations.

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.



Command and IO results


type 'a result = [ `Error of string | `Ok of 'a ] 
The type for command and IO results.
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 and
Raises Invalid_argument otherwise.
val on_error : ?level:Assemblage.Log.level -> use:'a -> 'a result -> 'a
on_error ~level ~use r is:
val ignore_error : use:'a -> 'a result -> 'a
ignore_error ~use r is like Assemblage.Cmd.on_error but the error is not logged.
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
Infix operators.

IO and file system operations


type path = Assemblage.Path.t 
module Path: sig .. end
Path operations.
module File: sig .. end
File operations.
module Dir: sig .. end
Directory operations.
module Vcs: sig .. end
Version control system operations.

Environment variables lookup


val env : string -> string option
env var is the value if the environment variable var, if defined.
val get_env : string -> string result
get_env var is like Assemblage.Cmd.env but returns an error if var is undefined.

Executing commands


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.