feat: Terminalwire.CLI — Thor-style command router#2
Merged
Conversation
Defining a CLI meant a `run(ctx)` handler with a hand-rolled `case Context.args`
dispatch — workable, but nowhere near as clean as Ruby/Thor's `desc`/`def`. Add a
small macro so the module reads like the commands themselves:
defmodule MyApp.CLI do
use Terminalwire.CLI, name: "my-app"
@desc "Greet someone by name"
def hello(name), do: puts("Hello, #{name}!")
end
Public functions become commands, their parameters become positional arguments, and
@desc becomes generated `help`. `use` generates `run/1` (mount it on WebSock as
before). Inside a command, puts/print/warn/gets/read_secret/env are imported and
bound to the session context (via the per-session process); `context/0` reaches the
rest (files, browser, raw terminal). Unknown command / wrong arity exits non-zero
with a usage hint. It's sugar over the plain handler, which still works for custom
parsing (Optimus, OptionParser).
- lib/terminalwire/cli.ex — the router (on_definition collects @desc'd defs +
their arg names for help; before_compile generates run/1).
- test/cli_test.exs — dispatch, multi-arg, exit codes, help, unknown/arity errors,
the imported helpers, the context guard, introspection (96% module coverage).
- README / moduledoc / CHANGELOG lead with the DSL; README value prop sharpened
(no API + no client + no release/auto-update pipeline to build).
Total coverage 92%; full suite 115 passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
use Terminalwire.CLI: public functions become commands, params become args,@descbecomes help — the Elixir analog of Thor'sdesc/def. Sugar over the existingrun/1handler (still usable for custom parsing). Newcli_test.exs(96% module coverage); README/moduledoc/CHANGELOG now lead with the DSL and the value prop is sharpened (no API + no client + no auto-update infra). Full suite 115 passed, total coverage 92%.