Skip to content

Repository files navigation

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

  • Declarative macro DSL for commands, options, arguments, and subcommands
  • Typed options and arguments with automatic coercion
  • Repeated (:multi), multi-value (:num_args), delimited (:value_delimiter), and hyphen-leading (:allow_hyphen_values) option values
  • Custom value parsers (:parse) that transform input into domain types
  • Per-param and cross-param validation, choices, conditional-required
  • Per-option relations (:conflicts_with, :requires) and param groups
  • Env var fallback, defaults (including :default_missing_value), boolean negation (--no-*)
  • Deprecation markers (deprecated) for options, arguments, and subcommands
  • Auto-generated help with headings, display order, before/after text, hidden items (hide), terminal-width wrapping, and color (respecting NO_COLOR)
  • Prefix inference and "Did you mean?" suggestions for mistyped commands and flags
  • Optional subcommands (:args_conflicts_with_subcommands) and external subcommands for git-style plugin dispatchers
  • Escript, Mix task (Cheer.MixTask), and long-running server entry points (Cheer.parse/3, Cheer.argv/0)
  • Shell completion for bash, zsh, fish, and PowerShell
  • REPL mode driven by the same command tree
  • In-process test runner with output capture
  • Command tree introspection (Cheer.tree/1) and markdown reference generation (Cheer.Reference)
  • Zero runtime dependencies

Install

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

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

About

A clap-inspired CLI framework for Elixir

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages