Argument Parsing

SolidGroundUX DocumentationSolidGroundUX
NL

Parse and manage command-line arguments for scripts

Source: target-root/usr/local/lib/solidgroundux/common/sgnd-args.sh

Parse and manage command-line arguments for scripts

Public functions

Internal functions
FunctionPurposeArgumentsOutput
_sgnd_lib_guardEnsure direct execution is rejected and record that the library has been sourced.——
_sgnd_arg_splitParse a pipe-separated argument specification into parser fields.- $1 — Argument specification in name\short\
_sgnd_arg_find_specLocate the effective argument specification for a long or short option.- $1 — Long option name or short option letter to find.Matching raw argument specification on stdout.
_sgnd_arg_validate_enumTest whether a supplied value is present in a comma-separated choice list.- $1 — Value to validate.—
_sgnd_arg_init_defaultsInitialize argument target variables from builtin and/or script argument specs.- $1 — Source selector: builtins, script, or both. Default: both—

Description

Provides a structured argument parsing system for SolidGroundUX scripts.

The library:

  • Parses short and long command-line arguments
  • Supports flags, values, and enumerated options
  • Maps arguments to strongly defined variables
  • Validates input against argument specifications
  • Separates framework arguments from script-specific arguments
  • Generates consistent help and usage output

Design principles

  • Declarative argument specification via SGND_ARGS_SPEC
  • Predictable and consistent parsing behavior across scripts
  • Clear separation between parsing and business logic
  • Minimal runtime surprises through validation and normalization

Role in framework

  • Core infrastructure for all executable scripts
  • Used during bootstrap to interpret command-line input
  • Enables standardized CLI behavior across the framework

Non-goals

  • Complex subcommand frameworks (e.g., git-style commands)
  • Interactive input handling (handled by ui-ask/ui-dlg)
  • Dynamic runtime argument schema mutation

Public API

var: Help layout settings

Purpose

Configure indentation used by sgnd_show_help when rendering section headers and option descriptions.

Variables: _header_indent Left padding for help section headers. _text_indent Left padding for option description lines.

Builtin framework argument specifications

var: SGND_BUILTIN_ARGS

Purpose

Define standard command-line options available to framework-enabled scripts.

Format: name|short|type|target_variable|help|default|choices

Notes:

  • type is flag, value, or enum.
  • enum choices are comma-separated.
  • Unset target variables are initialized by _sgnd_arg_init_defaults.
  • Existing state/config values are preserved until an explicit CLI option overrides them.

Builtin help examples

var: SGND_BUILTIN_EXAMPLES

Purpose

Provide reusable help examples for standard framework options.

Notes:

  • Examples may be merged with SGND_SCRIPT_EXAMPLES by sgnd_show_help.
  • SGND_SCRIPT_NAME is resolved lazily for display.