1.6.4 Module anvl_lib

A collection of functions useful for implementing conditions.

1.6.4.1 Types

filename_pattern()
-type filename_pattern() :: string().
template_vars()
-type template_vars() :: #{atom() | binary() =>
                               string()}.

1.6.4.2 Functions

hash(Term)
-spec hash(any()) -> binary().
exec_(Command, Args, Options)
-spec exec_(string(), [string()], list()) -> integer() |
                                             {integer(), iolist()}.

Execute a command and return exit code. If options list contains atom collect_output then this function will capture the output and return tuple {ExitCode, [Line, Line, ...]}. If it contains a tuple {search_path, false} then Command is treated as an absolute name.

Arguments:

  • Command: name of the executable (e.g. "ls")
  • Args: list of arguments passed to the executable (e.g. ["-a", "."])
  • Options: list of options passed to erlang:open_port/2
exec_(Cmd, Args)
-spec exec_(string(), [string()]) -> integer().

Equivalent to exec_(Cmd, Args, [])

exec(Cmd, Args, Opts)
-spec exec(string(), [string()], list()) -> true.

Execute a command and return true if it exits with code 0 or throw exit:unsat otherwise. By default this function searches for the executable in PATH. This can be disabled by passing {search_path, false} tuple in the options. Then Command will be treated as an absolute name.

Arguments:

  • Cmd: name of the executable (e.g. "ls")
  • Args: list of arguments passed to the executable (e.g. ["-a", "."])
  • Opts: list of additional options passed to erlang:open_port/2
exec(Cmd, Args)
-spec exec(string(), [string()]) -> true.

Equivalent to exec(Cmd, Args, []).

patsubst(Pattern, Src, Substitutions)
-spec patsubst(filename_pattern(), file:filename_all(),
               template_vars()) -> file:filename_all().

A special version of ‘template/3’ for manipulating file names. It automatically adds the following substitutions:

  • extension equal to the file extension of argument Src
  • basename equal to the basename of Src without the extension
  • dirname directory of Src

Example:

patsubst("${profile}/ebin/${basename}.beam", "src/foo.erl", #{profile => <<"debug">>}) ->
   <<"debug/ebin/foo.beam">>
patsubst(Pattern, Src)
-spec patsubst(filename_pattern(),
               file:filename_all()) -> file:filename_all().

Equivalent to patsubst(Pattern, Src, #{}).

template(Pattern, Substitutions, Type)
-spec template(iodata(), template_vars(),
               list) -> string();
              (iodata(), template_vars(), binary) -> binary();
              (iodata(), template_vars(), iolist) -> iodata();
              (iodata(), template_vars(), path) -> file:filename().

Substitute variables Substitutions in Pattern and return a value of the given type.

Example:

template("Foo = ${foo}, bar = ${bar}", #{foo => <<"1">>, <<"bar">> => <<"2">>}, binary) ->
    <<"Foo = 1, bar = 2">>
newer(EnsureDirs, Src, Target)
-spec newer(boolean(),
            file:filename_all() | [file:filename_all()],
            file:filename_all() |
            [file:filename_all()]) -> boolean().

Version of newer/2 that takes an additional argument that specifies whether to ensure directories for the target files or not.

max_mtime(L)
-spec max_mtime([file:filename_all()]) -> integer().

Returns maximum modification time for a set of files. Throws an exception if any input file doesn’t exist.

newer(Src, Target)
-spec newer(file:filename_all() | [file:filename_all()],
            file:filename_all() |
            [file:filename_all()]) -> boolean().

Returns true if any of the source files is newer than the target or if the target does not exist, false otherwise. This function assumes that the Target will be created, and creates the directory for the Target as a side effect. If this is not desirable, use anvl_lib:newer(false, Srcs, Targets) instead.


JavaScript license information