Skip to content

Args

Index

args::check_no_args

Die if called with any arguments.

Arguments

  • ... (caller's): arguments (count-checked; 0 expected)

args::check_at_most_1_arg

Die if called with more than 1 argument.

Arguments

  • ... (caller's): arguments (count-checked; ≤1 expected)

args::check_exactly_1_arg

Die if not called with exactly 1 argument.

Arguments

  • ... (caller's): arguments (count-checked; exactly 1 expected)

args::check_at_least_1_arg

Die if called with fewer than 1 argument.

Arguments

  • ... (caller's): arguments (count-checked; ≥1 expected)

args::check_at_most_2_args

Die if called with more than 2 arguments.

Arguments

  • ... (caller's): arguments (count-checked; ≤2 expected)

args::check_exactly_2_args

Die if not called with exactly 2 arguments.

Arguments

  • ... (caller's): arguments (count-checked; exactly 2 expected)

args::check_at_least_2_args

Die if called with fewer than 2 arguments.

Arguments

  • ... (caller's): arguments (count-checked; ≥2 expected)

args::check_at_most_3_args

Die if called with more than 3 arguments.

Arguments

  • ... (caller's): arguments (count-checked; ≤3 expected)

args::check_exactly_3_args

Die if not called with exactly 3 arguments.

Arguments

  • ... (caller's): arguments (count-checked; exactly 3 expected)

args::check_at_least_3_args

Die if called with fewer than 3 arguments.

Arguments

  • ... (caller's): arguments (count-checked; ≥3 expected)

args::check_at_most_4_args

Die if called with more than 4 arguments.

Arguments

  • ... (caller's): arguments (count-checked; ≤4 expected)

args::check_exactly_4_args

Die if not called with exactly 4 arguments.

Arguments

  • ... (caller's): arguments (count-checked; exactly 4 expected)

args::check_at_least_4_args

Die if called with fewer than 4 arguments.

Arguments

  • ... (caller's): arguments (count-checked; ≥4 expected)

args::has_num_args

Return true if called with exactly the given number of arguments.

Arguments

  • $1 (expected): count
  • ... (remaining): args (count-checked against $1)

Exit codes

  • 0: if remaining arg count equals $1
  • 1: otherwise

args::no_args

Return true if called with no arguments.

Arguments

  • ... (caller's): arguments

Exit codes

  • 0: if no args
  • 1: otherwise

args::has_at_least_num_args

Return true if called with at least the given number of arguments.

Arguments

  • $1 (minimum): count
  • ... (remaining): args (count-checked against $1)

Exit codes

  • 0: if remaining arg count is >= $1
  • 1: otherwise

args::check_for_stdin

Die if stdin has no data available (i.e., a terminal is attached). shellcheck disable=SC2120 # called with no args by callers, but shellcheck can't see all call sites

Function has no arguments.

args::stdin_exists

Return true if stdin has data available (i.e., not a terminal). shellcheck disable=SC2120 # called with no args by callers, but shellcheck can't see all call sites

Function has no arguments.

Exit codes

  • 0: if true
  • 1: if false

args::print_help

Print help text derived from the file-level shdoc header of the caller (or the given script path). Parses comment lines between the shebang and the first non-comment line for @description, @arg, @noargs, @stdout, @stderr, @exitcode, and @example tags. Multi-line continuations of @description and @example are preserved.

Arguments

  • $1 (path): Optional script path; defaults to "$0" (the caller).

Exit codes

  • 0: always.

Output on stdout

  • Formatted help text.

args::handle_help_flag

Scan caller's args for -h/--help; if found, print help via args::print_help and exit 0. Call early in a top-level script, before arg-count guards, so help works even when called with no other args.

Arguments

  • ... (caller's): arguments (forwarded verbatim)

Exit codes

  • 0: if -h/--help found (after printing help)