How rzcastilho/do_it works
Project type and purpose
• Project type: An Elixir library to build CLI applications.
• Purpose: Provide a set of macros (DoIt.MainCommand, DoIt.Command) and runtime modules to parse arguments/options, dispatch commands, generate help/version, and support shell auto‐completion.
• Key indicators: lib/do_it, mix/tasks, README describes macros, commands, escript/burrito packaging, completion features.
A. Core Library (lib/do_it)
– DoIt.MainCommand (macro)
– DoIt.Command (macro)
– Runner
– Argument, Option, Command, Subcommand modules
– Completion engine (DoIt.Completion)
– Introspection, Helper, Output, Exceptions
– Configuration loader (DoIt.Config/mix config)
B. Mix Tasks (lib/mix/tasks)
– do_it.config.init
– do_it.gen.completion
C. Packaging & Build
– Escript (Mix’s escript.build using :escript.main_module)
– Burrito‐Elixir (releases + Burrito.wrap)
D. Example Client (examples/hello_world)
– Uses MainCommand/Command to define HelloWorld CLI
– Drives EEx templates, subcommands, options
E. External Dependencies & Services
– Elixir/Erlang runtime
– EEx template engine
– Shell environments (bash, fish, zsh) for completion scripts
1. Compile-time:
• User Client code → invokes use DoIt.MainCommand or use DoIt.Command macros → Macro expansion generates command modules, dispatch functions, help/version handlers.
• Mix tasks (do_it.*) integrate into mix CLI to scaffold config or generate completion scripts.
2. Runtime:
• User types my_cli ... in shell → escript/Burrito wrapper invokes MainCommand.run(args) (Runner).
• Runner parses args → matches command/subcommand → invokes corresponding Command.run/3.
• DoIt.Argument and DoIt.Option modules handle parsing & validation.
• DoIt.Completion handles special completion commands and generates shell scripts.
• DoIt.Output handles printing to STDOUT/STDERR.
• Config subsystem (DoIt.Config) loads default templates or settings from config/*.exs or user’s context.
• Errors and help are managed by DoIt.Exceptions and auto-generated help routines.
Architectural patterns
• Macro-based code generation at compile time (metaprogramming).
• Layered design: Parsing → Dispatch → Execution → Output.
• Plugin-style extensibility via macros: users “plug in” new commands or subcommands.
• Command pattern: each module encapsulates a single action.
• Single binary entrypoint (escript/burrito) feeding into a generic runner.