View Source Runlet.CLI (runlet v1.2.5)

Compile runlet expressions

Summary

Functions

Add a runlet expression to the end of a pipeline.

Compile a runlet expression to AST

Compile a runlet expression to AST

Compile a runlet expression to AST.

Compile a runlet expression to AST.

Insert a runlet pipeline into another pipeline.

Tokenize a runlet expression.

Parse a runlet expression.

Add a runlet expression at the start of a pipeline.

Types

@type e() :: String.t() | [t()]
@type t() :: {[atom()], atom()} | {{[atom()], atom()}, [String.t() | integer()]}

Functions

@spec append(e(), e()) :: {:ok, [t()]} | {:error, String.t()}

Add a runlet expression to the end of a pipeline.

Examples

iex> Runlet.CLI.append(~s(test "foo" | bar 123 | another), ~s(insert | here))
{:ok,
 [{"test", ["foo"]}, {"bar", '{'}, {"another", []}, {"insert", []},
  {"here", []}]}
@spec compile(e()) :: {:ok, [t()]} | {:error, String.t()}

Compile a runlet expression to AST

Commands are looked up in the application environment:

Application.get_env(:runlet, :aliases, [])
Link to this function

compile(pipeline, commands)

View Source
@spec compile(e(), [t()]) :: {:ok, [t()]} | {:error, String.t()}

Compile a runlet expression to AST

Examples

iex> Runlet.CLI.compile(
...>   ~s(test "foo" | bar 123),
...>   [{"test", [{[:Fake, :Cmd, :AddArg], :exec},
...>              {{:Fake, :Cmd, :StaticArg}, ["static arg"]}]},
...>    {"bar", {[:Fake, :Cmd, :IntArg], :exec}}])
{:ok,
 {:|>, [context: Elixir, import: Kernel],
  [{:|>, [context: Elixir, import: Kernel],
    [{{:., [], [{:__aliases__, [alias: false], [:Fake, :Cmd, :AddArg]}, :exec]},
      [], ["foo"]},
     {{:., [],
       [{:__aliases__, [alias: false], {:Fake, :Cmd, :StaticArg}},
        ["static arg"]]}, [], ["foo"]}]},
   {{:., [], [{:__aliases__, [alias: false], [:Fake, :Cmd, :IntArg]}, :exec]},
    [], '{'}]}}
@spec compile!(e()) :: [t()]

Compile a runlet expression to AST.

Commands are looked up in the application environment:

Application.get_env(:runlet, :aliases, [])
Link to this function

compile!(pipeline, commands)

View Source
@spec compile!(e(), [t()]) :: [t()]

Compile a runlet expression to AST.

Examples

iex> Runlet.CLI.compile!(
...>   ~s(test "foo" | bar 123),
...>   [{"test", [{[:Fake, :Cmd, :AddArg], :exec},
...>              {{:Fake, :Cmd, :StaticArg}, ["static arg"]}]},
...>    {"bar", {[:Fake, :Cmd, :IntArg], :exec}}])
{:|>, [context: Elixir, import: Kernel],
 [{:|>, [context: Elixir, import: Kernel],
   [{{:., [], [{:__aliases__, [alias: false], [:Fake, :Cmd, :AddArg]}, :exec]},
     [], ["foo"]},
    {{:., [],
      [{:__aliases__, [alias: false], {:Fake, :Cmd, :StaticArg}},
       ["static arg"]]}, [], ["foo"]}]},
  {{:., [], [{:__aliases__, [alias: false], [:Fake, :Cmd, :IntArg]}, :exec]},
   [], '{'}]}
Link to this function

insert(pipeline, command, position)

View Source
@spec insert(e(), String.t() | [t()], integer()) ::
  {:ok, [t()]} | {:error, String.t()}

Insert a runlet pipeline into another pipeline.

Examples

iex> Runlet.CLI.insert(~s(test "foo" | bar 123 | another),
...>   ~s(insert | here), 2)
{:ok,
 [{"test", ["foo"]}, {"bar", '{'}, {"insert", []}, {"here", []},
  {"another", []}]}

Tokenize a runlet expression.

Examples

iex> Runlet.CLI.lex(~s(test "foo" | bar 123 | out > 456))
{:ok,
   [
     {:command, 1, "test"},
     {:string, 1, 'foo'},
     {:|, 1},
     {:command, 1, "bar"},
     {:integer, 1, 123},
     {:|, 1},
     {:command, 1, "out"},
     {:>, 1},
     {:integer, 1, 456}
   ], 1}
@spec parse(e()) ::
  {:ok, [{String.t(), [Runlet.PID.t() | String.t()]}]} | {:error, String.t()}

Parse a runlet expression.

Examples

iex> Runlet.CLI.parse(~s(test "foo" | bar 123 | out > 456))
{:ok, [{"test", ["foo"]}, {"bar", '{'}, {"out", []}, {">", [456]}]}
@spec prepend(e(), e()) :: {:ok, [t()]} | {:error, String.t()}

Add a runlet expression at the start of a pipeline.

Examples

iex> Runlet.CLI.prepend(~s(test "foo" | bar 123 | another), ~s(insert | here))
{:ok,
 [{"insert", []}, {"here", []}, {"test", ["foo"]}, {"bar", '{'},
  {"another", []}]}
Link to this function

substitute(list, fun, acc)

View Source