Parse framework or script command-line arguments

SolidGroundUX DocumentationSolidGroundUX
NL

fn: sgnd_parse_args

Purpose

Parse command-line options against the selected SolidGroundUX argument specification while preserving the remaining arguments for a later parse pass.

Behavior

  • Selects builtin, script, or combined argument specifications through SGND_ARGS_SOURCE (builtins, script, or both; default both).
  • Initializes defaults only for the argument specification selected for the current parse pass.
  • Parses recognized flag, value, and enum options and updates their declared target variables.
  • With --stop-at-unknown, stops at the first unrecognized option and preserves that option and the complete remaining command line in SGND_POSITIONAL.
  • With --preserve-unknown, consumes recognized options while preserving unrecognized options and positional values in their original order, then continues scanning so recognized options may appear anywhere before --.
  • Treats -- as the absolute end-of-options marker. Everything following it is positional data and is preserved without further option interpretation.
  • Enables bootstrap to extract framework builtins first and later parse the preserved script-specific arguments without imposing argument ordering.

Arguments

  • --stop-at-unknown — Optional parser mode; stop at the first option not present in the active specification and preserve the remainder.
  • --preserve-unknown — Optional parser mode; preserve arguments not present in the active specification and continue parsing later recognized options.
  • $@ — Command-line arguments to parse after optional parser mode switches.

Inputs (globals)

  • SGND_ARGS_SOURCE
  • SGND_BUILTIN_ARGS
  • SGND_ARGS_SPEC

Outputs (globals)

  • SGND_POSITIONAL
  • SGND_EFFECTIVE_ARGS_SPEC
  • Target variables declared by the selected argument specification.

Returns

  • 0 when parsing succeeds.
  • 1 for unknown options in strict mode, missing values, invalid enum values, or malformed argument specifications.

Usage

  SGND_ARGS_SOURCE=builtins sgnd_parse_args --preserve-unknown "$@"
  SGND_ARGS_SOURCE=script sgnd_parse_args "${SGND_POSITIONAL[@]}"