Marea.Config.Args (marea v0.0.1-rc.1)

Copy Markdown View Source

CLI argument assembly and parsing.

Plugins enrich a shared %{options:, flags:, subcommands:} map through the Marea.Plugins.Base.marea_config_args/1 chain (using add_options/2, add_flags/2, add_subcommands/2). build_optimus/1 then turns the final map into an Optimus parser, propagating any options/flags marked global: true down to every leaf subcommand.

This module also exposes a small set of reusable option specs (deploy_option/0, release_option/0, cookie_option/0, pos_option/0, mix_env_option/1) used across the built-in plugins.

Summary

Types

Args config map enriched by the Marea.Plugins.Base.marea_config_args/1 plugin chain.

An {name, opts} Optimus option/flag/subcommand spec.

Functions

Appends new_flags to the args config. Use from Marea.Plugins.Base.marea_config_args/1.

Appends new_options to the args config. Use from Marea.Plugins.Base.marea_config_args/1.

Adds new_subcommands to the args config. Use from Marea.Plugins.Base.marea_config_args/1.

Returns the base args config map that plugins enrich via Marea.Plugins.Base.marea_config_args/1.

Runs the Marea.Plugins.Base.marea_config_args/1 chain on a list of plugin modules, returning the accumulated args map.

Builds an Optimus parser from the final (plugin-enriched) args config.

Reusable spec for the --cookie option (defaults to marea_cookie).

Reusable spec for the --deploy / -d option.

Reusable spec for --mix-env. If default is given, it is used when the option is missing.

Parses args against optimus, returning {cmds, options, flags}.

Reusable spec for --pos (integer; used to run multiple instances side-by-side).

Reusable spec for the --release / -r option.

Types

args()

@type args() :: %{options: keyword(), flags: keyword(), subcommands: keyword()}

Args config map enriched by the Marea.Plugins.Base.marea_config_args/1 plugin chain.

spec()

@type spec() :: {atom(), keyword()}

An {name, opts} Optimus option/flag/subcommand spec.

Functions

add_flags(args, new_flags)

@spec add_flags(
  args(),
  keyword()
) :: args()

Appends new_flags to the args config. Use from Marea.Plugins.Base.marea_config_args/1.

add_options(args, new_options)

@spec add_options(
  args(),
  keyword()
) :: args()

Appends new_options to the args config. Use from Marea.Plugins.Base.marea_config_args/1.

add_subcommands(args, new_subcommands)

@spec add_subcommands(
  args(),
  keyword()
) :: args()

Adds new_subcommands to the args config. Use from Marea.Plugins.Base.marea_config_args/1.

Merges by key so multiple plugins can extend the same parent subcommand (e.g. Marea.Plugins.Docker and Marea.Plugins.Helm both contribute children under build). For an already-present parent, the new entry's :subcommands / :options / :flags are appended, and other keys (:name, :about, …) keep the first writer's value. Top-level entries that don't yet exist are appended at the end.

base_args()

@spec base_args() :: args()

Returns the base args config map that plugins enrich via Marea.Plugins.Base.marea_config_args/1.

Includes the global --marea-dir, --state-dir, --help, --nopause options/flags, and an empty subcommands list.

build_args_tree(plugins)

@spec build_args_tree([module()]) :: args()

Runs the Marea.Plugins.Base.marea_config_args/1 chain on a list of plugin modules, returning the accumulated args map.

Unlike Malla.local/3, this does not require a running Malla.Service: every plugin's marea_config_args/1 is a plain function generated by defcb, so we can fold over them directly. Used by the MCP server to expose tool descriptors without spinning up the full service.

All marea_config_args/1 implementations are expected to return {:cont, [args]}; any other shape is ignored (matching the default in Marea.Plugins.Base).

build_optimus(args_config)

@spec build_optimus(args()) :: Optimus.t()

Builds an Optimus parser from the final (plugin-enriched) args config.

deploy_option()

@spec deploy_option() :: spec()

Reusable spec for the --deploy / -d option.

mix_env_option(default \\ nil)

@spec mix_env_option(String.t() | nil) :: spec()

Reusable spec for --mix-env. If default is given, it is used when the option is missing.

parse!(optimus, args)

@spec parse!(Optimus.t(), [String.t()]) :: {[atom()], map(), map()} | no_return()

Parses args against optimus, returning {cmds, options, flags}.

Normalizes --help/-h placement so that marea aws --help becomes marea help aws, and aborts with a clear error on unknown options or parse failures.

pos_option()

@spec pos_option() :: spec()

Reusable spec for --pos (integer; used to run multiple instances side-by-side).

release_option()

@spec release_option() :: spec()

Reusable spec for the --release / -r option.