package bos
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=8c27b2cbc89a9e7ca32ecf8b232ab5c8c91c395dc4d1916cc9ddbe8c3a8e20e8
md5=aeae7447567db459c856ee41b5a66fd2
doc/bos.setup/Bos_setup/Cmd/index.html
Module Bos_setup.Cmd
include module type of struct include Bos.Cmd end
Command line fragments
type t = Bos.Cmd.tThe type for command line fragments.
val v : string -> tv cmd is a new command line (or command line fragment) whose first argument is cmd.
val empty : tempty is an empty command line.
val is_empty : t -> boolis_empty l is true iff l is empty.
val p : Fpath.t -> stringp is Fpath.to_string. This combinator makes path argument specification brief.
Command lines
val line_tool : t -> string optionline_tool l is l's first element, usually the executable tool name or file path.
val line_args : t -> string listline_args is l's command line arguments, the elements of l without the command name.
val line_exec : t -> string optionval get_line_exec : t -> stringPredicates and comparison
Conversions and pretty printing
val of_string : string -> (t, Rresult.R.msg) Rresult.resultof_string s tokenizes s into a command line. The tokens are recognized according to the token production of the following grammar which should be mostly be compatible with POSIX shell tokenization.
white ::= ' ' | '\t' | '\n' | '\x0B' | '\x0C' | '\r' squot ::= '\'' dquot ::= '\"' bslash ::= '\\' tokens ::= white+ tokens | token tokens | ϵ token ::= ([^squot dquot white] | squoted | dquoted) token | ϵ squoted ::= squot [^squot]* squot dquoted ::= dquot (qchar | [^dquot])* dquot qchar ::= bslash (bslash | dquot | '$' | '`' | '\n')
qchar are substitued by the byte they escape except for '\n' which removes the backslash and newline from the byte stream. squoted and dquoted represent the bytes they enclose.
val to_string : t -> stringto_string l converts l to a string that can be passed to the command(3) POSIX system call.
val to_list : t -> string listto_list l is l as a list of strings.
val of_list : ?slip:string -> string list -> tof_list ?slip l is a command line from the list of arguments l. If slip is specified it is added on the command line before each element of l.
val of_values : ?slip:string -> ('a -> string) -> 'a list -> tof_values ?slip conv l is like of_list but acts on a list of values, each converted to an argument with conv.
val pp : Format.formatter -> t -> unitpp ppf l formats an unspecified representation of l on ppf.
val dump : Format.formatter -> t -> unitdump ppf l dumps and unspecified representation of l on ppf.
Examples
let ls path = Cmd.(v "ls" % "-a" % p path)
let tar archive path = Cmd.(v "tar" % "-cvf" % p archive % p path)
let opam cmd = Cmd.(v "opam" % cmd)
let opam_install pkgs = Cmd.(opam "install" %% of_list pkgs)
let ocamlc ?(debug = false) file =
Cmd.(v "ocamlc" % "-c" %% on debug (v "-g") % p file)
let ocamlopt ?(profile = false) ?(debug = false) incs file =
let profile = Cmd.(on profile @@ v "-p") in
let debug = Cmd.(on debug @@ v "-g") in
let incs = Cmd.of_list ~slip:"-I" incs in
Cmd.(v "ocamlopt" % "-c" %% debug %% profile %% incs % p file)