package yocaml
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=89a74bd5cb37e580e45e4ed3d43b07b2cca5af9ab7f98966c48fe9730dc4af2e
sha512=ae77555570320c28c47d748e75056ccc44bb43cddf6fef70e8b556254fd809d67b915b313bd1833c28581db1fdeefbe34e81d5548744d6ecabe466ee1ef6284c
doc/yocaml/Yocaml/Cmd/index.html
Module Yocaml.CmdSource
Used to describe Unix-style commands for executing arbitrary shell commands. It is up to the Runtime to use this representation to be cross-platform (for example, to use it with Windows).
The library does not ensure typeafety but should be expressive enough to describe many CLI calls (and can serve as a basis for slightly stricter libraries).
Types
The way an order is structured respects this logic: cmd_name -a --b foo bar1 bar2:
cmd_nameis the command name (and is a regular string).-ais a flag and has the typearg--b foois param and has the typearg.foo,bar1andbar2arevalues, with typevalue.
A value can be a plain text or a Yocaml.Path.t (that can be watched to form a dependency set).
# make "a-complicated_command" [
flag "f";
flag "w";
param ~suffix:"=" "priority" @@ s "high";
param "into" @@ w (Yocaml.Path.rel ["foo"; "bar"; "baz"]);
arg @@ list ["a"; "b"; "c"; "d"]
] ;;
- : t =
a-complicated_command -f -w --priority=high --into ./foo/bar/baz a b c dDescribe a full command.
Describe an argument of a command.
Describe a value.
Building commands
Building Arguments
flag ?prefix name build a shell flag. The default prefix is -. Ie: flag "foo" is "-foo", but flag ~prefix:"--T" "foo" is "--Tfoo".
# flag "foo" ;;
- : arg = -foo
# flag ~prefix:"--T" "foo" ;;
- : arg = --Tfooparam ?prefix ?suffix key value build a shell labeled argument. The default prefix is -- and the default suffix is " ". A param use the following scheme: prefix^key^suffix^value. Ie: param "foo" (string "bar") is --foo bar, but param ~prefix:"--T" ~suffix:"=" "foo" (int 10) is --Tfoo=10.
# param "foo" @@ string "bar" ;;
- : arg = --foo bar
# param ~prefix:"--T" ~suffix:"=" "foo" @@ int 10 ;;
- : arg = --Tfoo=10arg x create a plain argument. Ie: arg (string "foo") is foo. Value can be used to deal with non-structured argument, ie: arg (string "--a b --c -d -eee") seems perfectly valid.
Building values
list ?sep values collapse a list of string into one argument. By default sep is a space.
The function does not lift an arbitrary list of values, as this would result in the loss of observable paths.
path ?watched p build a value from a path p. If watched is true, the path can be observed as a dependency. (by default, watched is false. )
Shortcuts
As it can be boring to build complex commands, the API provides a few shortcuts:
Dependencies
When a path is provided to a command, it may or may not be observed as a dependency.
deps_of cmd gives the set of observed dependencies. For example :
# deps_of @@ make "foo" [
param "input" @@ w (Yocaml.Path.rel ["a"; "b"; "c.txt"])
; param "with" @@ w (Yocaml.Path.rel ["deps.txt"])
; param "output" @@ p (Yocaml.Path.rel ["out"; "abc.txt"])
] ;;
- : Yocaml.Path.t list = [./a/b/c.txt; ./deps.txt](The output path is not watched).
Helpers
Pretty-printer for cmd.
Pretty-printer for arg.