Alaja.CLI.Parser (Alaja v1.0.0)

Copy Markdown View Source

Shared parsing utilities for CLI commands.

Handles repeated flags, quoted values, environment variables, color parsing, and other common patterns.

Summary

Functions

Collects all values for a repeated --flag from raw args.

Parses an alignment string into an atom.

Parses a color string using the Drawer colour system. Returns {:ok, {r,g,b}} or {:error, reason}.

Parses a semicolon-separated list of colors. Returns {:ok, [{r,g,b}, ...]} or {:error, message}.

Parses a color and returns the RGB tuple, or prints error to stderr and returns nil.

Parses a KEY=VALUE string into a tuple.

Functions

collect_repeated(args, flag)

@spec collect_repeated([String.t()], String.t()) :: [String.t()]

Collects all values for a repeated --flag from raw args.

Supports both --flag value and --flag=value forms.

parse_align(a)

@spec parse_align(String.t() | atom() | nil) :: :left | :center | :right

Parses an alignment string into an atom.

parse_color(str)

@spec parse_color(String.t() | nil) ::
  {:ok, {byte(), byte(), byte()}} | {:error, term()} | nil

Parses a color string using the Drawer colour system. Returns {:ok, {r,g,b}} or {:error, reason}.

parse_color_list(str)

@spec parse_color_list(String.t() | nil) ::
  {:ok, [tuple()]} | {:error, String.t()} | nil

Parses a semicolon-separated list of colors. Returns {:ok, [{r,g,b}, ...]} or {:error, message}.

parse_color_opt(str)

@spec parse_color_opt(String.t() | nil) :: {byte(), byte(), byte()} | nil

Parses a color and returns the RGB tuple, or prints error to stderr and returns nil.

parse_env_pair(pair)

@spec parse_env_pair(String.t()) :: {atom(), String.t()} | nil

Parses a KEY=VALUE string into a tuple.