View Source Tux.Quick (Tux v0.4.0)
Utility macros for generating hierarchical, compact skeletons of simple programs
used for testing purposes without going the traditional route of creating
the modules with Tux.Dispatcher, Tux.Command, etc.
program/2- generate a top level dispatcher moduleprogram/1- return the Elixir module name generated byprogram/2dispatcher/2- generate and register a dispatcher module with a given name, inside a parent dispatchercommand/2- generate and register a command module with a given name
Example
Here's an example of a simple CLI tool built using this module's macros:
defmodule Tool do
import Tux.Quick
program "cli" do
command "hello", do: {:ok, "hello world"}
dispatcher "ping" do
command "once", do: {:ok, "pong"}
command "twice", do: {:ok, "pong pong"}
end
end
defdelegate main(args), to: program("cli")
endUpdate your mix.exs to define the escript, build it with mix escript.build,
and then finally run it:
$ mix escript.build
$ ./tool hello
hello
$ ./tool ping once
pong
$ ./tool ping twice
pong pong
Summary
Functions
Construct a Tux.Command module inside a dispatcher module.
Construct a Tux.Dispatcher module and register it with the given name as
a command module within the context of its parent dispatcher.
Return the name of a module which was created with program/2
Construct a top-level dispatcher module with no registered commands,
inside which you can define other tux structures such as dispatchers
and commands using the dispatcher/2 and command/2 macros.
Functions
Construct a Tux.Command module inside a dispatcher module.
command "ping" do
{:ok, "pong"}
endYou can also supply the registration options you'd normally supply
to the Tux.Dispatcher.cmd/3 macro:
command "ping", preloads: [...] do
{:ok, "pong"}
end
Construct a Tux.Dispatcher module and register it with the given name as
a command module within the context of its parent dispatcher.
dispatcher "foo" do
command "ping", do: {:ok, "pong"}
endThis macro also accepts the usual Tux.Dispatcher options:
dispatcher "foo", rescue: true, ... do
...
end
Return the name of a module which was created with program/2:
iex> import Tux.Quick
...> program("mytool")
:"Elixir.mytool"
iex> import Tux.Quick
...> program(:another)
:"Elixir.another"
Construct a top-level dispatcher module with no registered commands,
inside which you can define other tux structures such as dispatchers
and commands using the dispatcher/2 and command/2 macros.
program "foo" do
dispatcher "bar" do
command "ping", do: {:ok, "pong"}
end
endThis macro also accepts the usual Tux.Dispatcher options:
program "foo", rescue: true do
...
endTo return the name of module generated with this macro use program/1.