Follow-up to #132.
A command tree consumed only through Cheer.parse/3 never needs run/2. The
compiler still warns:
warning: HexpmMcp.CLI is a leaf command (no subcommands) but does not implement run/2
lib/hexpm_mcp/cli.ex:1: HexpmMcp.CLI (module)
run: 2 is in @optional_callbacks, so the behaviour already treats it as
optional; only the DSL compiler's leaf check disagrees.
This blocks the exact pattern parse/3 was added for. Projects that build with
mix compile --warnings-as-errors (which hexpm-mcp does, joshrotenberg/hexpm-mcp#68)
have to define a run/2 they never call in order to compile, which is the stub
#132 set out to remove.
Why it can't just be dropped
The warning is right for run/3 users: a leaf with no handler means dispatch
reaches a dead end at runtime. The compiler cannot tell which entry point a
consumer will use, so the intent has to be declared.
Suggestion
A DSL marker inside the command block:
command "hexpm_mcp" do
parse_only()
about "MCP server for hex.pm and hexdocs.pm"
option :transport, type: :string, choices: ["stdio", "http"]
end
Suppresses the leaf warning, and could reasonably make Cheer.run/3 raise a
clear error for that command rather than failing obscurely.
use Cheer.Command, parse_only: true would work too, though the DSL form keeps
it next to the rest of the command's declaration.
Whatever the spelling, the cookbook entry from #133 should use it, since a
long-running server is precisely the case that has no run/2.
Follow-up to #132.
A command tree consumed only through
Cheer.parse/3never needsrun/2. Thecompiler still warns:
run: 2is in@optional_callbacks, so the behaviour already treats it asoptional; only the DSL compiler's leaf check disagrees.
This blocks the exact pattern
parse/3was added for. Projects that build withmix compile --warnings-as-errors(which hexpm-mcp does, joshrotenberg/hexpm-mcp#68)have to define a
run/2they never call in order to compile, which is the stub#132 set out to remove.
Why it can't just be dropped
The warning is right for
run/3users: a leaf with no handler means dispatchreaches a dead end at runtime. The compiler cannot tell which entry point a
consumer will use, so the intent has to be declared.
Suggestion
A DSL marker inside the
commandblock:Suppresses the leaf warning, and could reasonably make
Cheer.run/3raise aclear error for that command rather than failing obscurely.
use Cheer.Command, parse_only: truewould work too, though the DSL form keepsit next to the rest of the command's declaration.
Whatever the spelling, the cookbook entry from #133 should use it, since a
long-running server is precisely the case that has no
run/2.