Cheer

CI Hex.pm Hex Docs License

A clap-inspired CLI framework for Elixir. Define your command tree once and get parsing, validation, help, shell completion, a REPL, and in-process testing for free.

30-second taste

defmodule MyApp.CLI.Greet do
  use Cheer.Command

  command "greet" do
    about "Greet someone"

    argument :name, type: :string, required: true, help: "Who to greet"
    option :loud, type: :boolean, short: :l, help: "SHOUT"
  end

  @impl Cheer.Command
  def run(%{name: name} = args, _raw) do
    greeting = "Hello, #{name}!"
    if args[:loud], do: String.upcase(greeting), else: greeting
  end
end

Cheer.run(MyApp.CLI.Greet, ["world", "--loud"], prog: "greet")
# "HELLO, WORLD!"

Features

Install

def deps do
  [{:cheer, "~> 0.2.3"}]
end

To keep the DSL paren-free under mix format, import cheer's formatter settings in your .formatter.exs:

[
  import_deps: [:cheer],
  inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

Documentation

Full docs on hexdocs.pm/cheer:

Runnable examples

Standalone Mix projects that match the cookbook entries live under examples/:

cd examples/greeter && mix deps.get
mix run -e 'Greeter.CLI.main(["world", "--loud", "--times", "3"])'

License

MIT