Use Livebook to open this notebook and explore new ideas.
It is easy to get started, on your machine or the cloud.
# Simple Example
```elixir
Mix.install([
{:prompt, "~> 0.9.3"}
])
```
## Starting Out
Lets go through an example of creating and building a new commandline/terminal app with `Prompt` that will acknowledge a person.
Lets call it `ack`.
<!-- livebook:{"break_markdown":true} -->
Lets define a `CLI` module and create where we can define what arguments we allow and what options are available for our tool.
```elixir
defmodule CLI do
@moduledoc """
DOCUMENTATION FOR THE TOOL
"""
use Prompt.Router, otp_app: :ack
command :hello, HelloCommand do
arg(:help, :boolean)
end
end
```
## Now Create the Command Handler
Now we'll have to create the handler for the `hello` command.
```elixir
defmodule HelloCommand do
@moduledoc """
The help message
ack hello <name>
--help prints this help message
"""
use Prompt.Command
@impl true
def init(opts) do
# opts is map of data which includes the
# options for the command and any other data passed in
# Our opts here look like give the following incanatation `ack hello bob`:
# `%{help: false, leftover: ["bob"]}
# `init/1` can be used to transform any arguments if needed.
Map.put(opts, :name, List.first(opts.leftover, nil))
end
@impl true
def process(%{help: true}), do: help()
def process(%{name: name}) do
display("Hello #{name}", color: :green)
end
end
```
## Simulate calling the CLI
```elixir
CLI.main(["hello", "bob"])
```
```elixir
CLI.main(["hello", "--help"])
```
## Bundle and Distribute
To build your app, you'll need to decide if you want an escript or a binary. The former will require
the user of your tool to have Elixir and Erlang installed on their system. A binary built using
Bakeware or Burrito can be distributed and used without having Elixir or Erlang on the system.
See the [documentation](https://hexdocs.pm/prompt/Prompt.html#module-building-for-distribution) for details on both
See source