Skip to content

feat: add Cheer.argv/0 for Burrito-aware argv #131

Description

@joshrotenberg

Problem

A Burrito-wrapped binary does not populate System.argv/0. Arguments arrive
through Burrito.Util.Args.argv/0 instead, and Burrito.Util.running_standalone?/0
is what tells you which mode you are in. Every Cheer app that ships via Burrito
therefore writes the same shim:

defp argv do
  if Code.ensure_loaded?(Burrito.Util) and Burrito.Util.running_standalone?() do
    Burrito.Util.Args.argv()
  else
    System.argv()
  end
end

tinfoil_demo hand-writes it. hexpm-mcp is about to write the same thing
(joshrotenberg/hexpm-mcp#68). Anyone using the burrito + tinfoil + cheer stack
hits it.

The failure mode when you get it wrong is silent rather than loud: System.argv/0
returns [], every option falls through to its default, and the binary does
something plausible but wrong. In hexpm-mcp's case --transport stdio would
have fallen through to the :http default and started a web server while the
MCP client waited forever for a stdio handshake.

Proposal

@spec argv() :: [String.t()]
def argv()

Returns Burrito.Util.Args.argv/0 when running as a standalone Burrito binary,
System.argv/0 otherwise.

Cheer keeps its zero-runtime-dependency property by resolving Burrito through
Code.ensure_loaded?/1 rather than taking a dep.

Notes

Cheer.main/3 should probably default to this rather than requiring the caller
to pass argv in, though the explicit-argv form has to keep working for tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions