From d7ca0092677482ef569e1e954b9504f73caae831 Mon Sep 17 00:00:00 2001 From: Ramesh Padmanabhaiah Date: Wed, 15 Jul 2026 22:45:29 -0700 Subject: [PATCH] Document and normalize the public Bash API --- README.md | 11 ++-- lib/bash/arg/README.md | 5 +- lib/bash/file/README.md | 14 +++-- lib/bash/gh/README.md | 9 +++ lib/bash/git/README.md | 26 ++++---- lib/bash/git/lib_git.sh | 38 ++++++------ lib/bash/git/tests/lib_git.bats | 56 +++++++++--------- lib/bash/list/README.md | 14 ++--- lib/bash/std/README.md | 102 ++++++++++++++++++++++++++++++++ lib/bash/std/lib_std.sh | 40 ++++++------- lib/bash/std/tests/lib_std.bats | 18 +++--- lib/bash/str/README.md | 20 +++---- tests/validate.sh | 22 +++++++ 13 files changed, 259 insertions(+), 116 deletions(-) diff --git a/README.md b/README.md index 5d66cd2..6cb2905 100644 --- a/README.md +++ b/README.md @@ -25,17 +25,18 @@ Requires Bash 4.2+. On macOS, use Homebrew Bash instead of the system `/bin/bash File editing helpers built on the stdlib, including idempotent marker-delimited file section updates. - [`lib/bash/git/lib_git.sh`](lib/bash/git/README.md) - Git helper functions built on the stdlib for lightweight repository - inspection, update, and script freshness checks. + Git helper functions built on the stdlib for default-branch, worktree, + upstream, remote, repository update, and script freshness checks. - [`lib/bash/gh/lib_gh.sh`](lib/bash/gh/README.md) GitHub CLI helper functions built on the stdlib for command readiness, - authentication diagnostics, and checked `gh` execution. + authentication diagnostics, remote parsing, API retries, and checked `gh` + execution. - [`lib/bash/str/lib_str.sh`](lib/bash/str/README.md) String helpers built on the stdlib for case conversion, trimming, predicates, splitting, and joining. - [`lib/bash/arg/lib_arg.sh`](lib/bash/arg/README.md) - Argument parsing helpers built on the stdlib for exact flag and value - options without hidden parser globals. + Argument parsing helpers built on the stdlib for exact flag, scalar value, + and repeatable value options without hidden parser globals. - [`lib/bash/list/lib_list.sh`](lib/bash/list/README.md) Indexed-array helpers built on the stdlib for in-place mutation, membership checks, deduplication, and length results. diff --git a/lib/bash/arg/README.md b/lib/bash/arg/README.md index 35701f3..07a4eb9 100644 --- a/lib/bash/arg/README.md +++ b/lib/bash/arg/README.md @@ -9,8 +9,11 @@ helpers are available. ## Public API -- `arg_parse` +- `arg_parse -- [args...]` Parse exact flag, value, and repeatable options into caller-owned arrays. + Returns `0` on success and `2` for malformed specs, unknown options, or + missing values; caller-owned outputs are published only after a successful + parse. ## Usage diff --git a/lib/bash/file/README.md b/lib/bash/file/README.md index 6c4ccce..5e110eb 100644 --- a/lib/bash/file/README.md +++ b/lib/bash/file/README.md @@ -8,14 +8,18 @@ Source `lib/bash/std/lib_std.sh` before this library so logging and error helper ## Public API -- `file_section_exists` +- `file_section_exists ` Inspect whether a valid marker-delimited block is present without changing - the file. -- `file_section_needs_update` + the file; returns `0` for present, `1` for absent, and `2` for invalid + marker order or counts. +- `file_section_needs_update [content...]` Inspect whether adding or replacing a marker-delimited block would change the - file. -- `update_file_section` + file; returns `0` when an update is needed, `1` when unchanged, and `2` for + invalid marker order or counts. +- `update_file_section [-r|content...]` Idempotently add, replace, or remove a marker-delimited block inside a file. + It mutates the target or symlink referent and returns nonzero on validation or + filesystem failure. ## Usage diff --git a/lib/bash/gh/README.md b/lib/bash/gh/README.md index bf82bdd..948f27e 100644 --- a/lib/bash/gh/README.md +++ b/lib/bash/gh/README.md @@ -43,8 +43,17 @@ import "/path/to/base-bash-libs/lib/bash/gh/lib_gh.sh" 502/503/504-style failures. `BASE_GH_API_MAX_ATTEMPTS` defaults to `2`. `BASE_GH_API_RETRY_DELAY_SECONDS` defaults to `2` when the error output does not include a `Retry-After` value. + +All GitHub helper failures return a nonzero status and preserve the underlying +`gh` status where applicable. The remote parser and origin inference helpers +leave caller-owned result variables unchanged on failure; use `--optional` with +`gh_infer_repo_from_origin` when a missing or non-GitHub origin is expected. ## Boundary This library is intentionally generic. It does not know about Base branch names, issue categories, GitHub Project fields, repository baselines, generated pull request bodies, or any other Base workflow policy. + +## Tests + +BATS coverage lives in `lib/bash/gh/tests/lib_gh.bats`. diff --git a/lib/bash/git/README.md b/lib/bash/git/README.md index f6a2c07..c02410a 100644 --- a/lib/bash/git/README.md +++ b/lib/bash/git/README.md @@ -8,30 +8,32 @@ Source `lib/bash/std/lib_std.sh` before this library so logging and shared error ## Public API -- `git_update_repo` +- `git_update_repo [allowed_dirty_path] [expected_branch]` Update a repository on its detected default branch, optionally allowing tracked changes in one specific path. -- `git_get_current_branch` +- `git_get_current_branch ` Return the current branch name through a caller-provided variable, or `detached head`. -- `git_detect_default_branch` +- `git_detect_default_branch ` Detect a repository's default branch from its remote HEAD and standard local fallbacks. -- `git_worktree_path_for_branch` +- `git_worktree_path_for_branch [repo]` Print the worktree path attached to a local branch. -- `git_list_worktree_branches` +- `git_list_worktree_branches [repo]` Print tab-separated worktree path and branch rows. -- `git_branch_upstream` +- `git_branch_upstream ` Print the configured upstream ref for a local branch. -- `git_branch_merged_to_ref` +- `git_branch_merged_to_ref ` Check whether a local branch is an ancestor of a ref. -- `git_list_remote_branches` +- `git_list_remote_branches [repo]` Print branch names from the `origin` remote. -- `check_script_up_to_date` +- `check_script_up_to_date [--fetch]