Convert the scripts into a CLI app — pbd, installable via Homebrew - #5
Open
jeffreybaird wants to merge 1 commit into
Open
Convert the scripts into a CLI app — pbd, installable via Homebrew#5jeffreybaird wants to merge 1 commit into
pbd, installable via Homebrew#5jeffreybaird wants to merge 1 commit into
Conversation
…into
The tool was four scripts you ran out of a checkout. It is now one command with
subcommands, laid out the way the bash CLIs it scaffolds are laid out
(scripts/new-bash-cli.sh): bin/pbd parses arguments and dispatches, lib/pbd/
does the work, test/run.sh drives the real executable.
pbd bootstrap ~/src/myapp pbd gitea bootstrap
pbd check ~/src/myapp pbd gitea teardown
pbd teardown ~/src/myapp pbd config
THE ACTUAL CONVERSION is splitting one $SCRIPT_DIR into three paths. Every
script used to compute it once and use it for two unrelated jobs: finding the
templates it ships, and keeping the user's own files. That works when the tool
IS a checkout; it does not survive being installed, because a Homebrew prefix
is not a place to write logs and cached admin tokens. So:
PBD_ROOT read-only, ships with the tool — templates and library
PBD_STATE_DIR writable, the user's — transcripts, cached Gitea credentials
($XDG_STATE_HOME/pbd)
the env file searched for (--env-file, $XDG_CONFIG_HOME/pbd/env,
$PBD_ROOT/.env) rather than assumed to sit beside the script
A checkout that has been caching a Gitea admin token beside the script keeps
it: the first run moves it into the state directory instead of minting a second
admin account. The current directory is deliberately not searched for an env
file — app directories carry their own unrelated .env, and picking one up as
DigitalOcean credentials would provision against the wrong account silently.
The install layout is the checkout layout, so one code path serves both: bin/
lib/ scripts/ and the template roots go into libexec unchanged, and bin/pbd is
symlinked onto the PATH from there. Following that symlink to the real file is
what lets an installed pbd find its own library — the test suite runs the
command through a symlink and out of a copied prefix for exactly that reason.
Also:
- the .env precedence loader, copy-pasted into all four scripts, is one
function in lib/pbd/common.sh
- usage errors exit 2, not 1 — the contract this tool holds every CLI it
generates to, and it now holds itself to
- every command answers --help for itself; `pbd config` prints the three paths
- ./bootstrap.sh, ./teardown.sh, ./bootstrap-gitea.sh and ./teardown-gitea.sh
are kept as forwarding shims, so existing notes and shell history still work
- Formula/pbd.rb installs it (`brew install --HEAD`), with terraform noted as a
caveat since it is BUSL and out of homebrew-core
- .github/workflows/ci.yml runs shellcheck, the suite, and `brew style` — the
same lint-and-test pipeline this tool demands of every app it scaffolds
No deploy behavior changes: the modules are the same code, with SCRIPT_DIR
renamed, the env block lifted out, and main() renamed to the function bin/pbd
calls.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0134vzTxuJJKuRdsu5iyysmz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The tool was four scripts you ran out of a checkout. It is now one command with subcommands, laid out the way the bash CLIs it scaffolds are laid out (
scripts/new-bash-cli.sh):bin/pbdparses arguments and dispatches,lib/pbd/does the work,test/run.shdrives the real executable.The actual conversion: splitting
$SCRIPT_DIRinto three pathsEvery script computed one
$SCRIPT_DIRand used it for two unrelated jobs: finding the templates it ships, and keeping the user's own files (.env,bootstrap.log, the cached Gitea admin token). That works when the tool is a checkout; it does not survive being installed — a Homebrew prefix is not a place to write logs and secrets. So:PBD_ROOTlibexecwhen installedPBD_STATE_DIR$XDG_STATE_HOME/pbd--env-file/~/.config/pbd/env/$PBD_ROOT/.env, searched in that orderThe install layout is the checkout layout, so one code path serves both: the tree goes into
libexecunchanged andbin/pbdis symlinked onto the PATH. Following that symlink to the real file is what lets an installedpbdfind its own library — the test suite runs the command through a symlink and out of a copied prefix for exactly that reason.A checkout that has been caching a Gitea admin token beside the script keeps it: the first run moves it into the state directory instead of minting a second admin account. The current directory is deliberately not searched for an env file — app directories carry their own unrelated
.env, and picking one up as DigitalOcean credentials would provision against the wrong account silently.Also
.envprecedence loader, copy-pasted into all four scripts, is now one function inlib/pbd/common.sh.--help;pbd configprints the three paths../bootstrap.sh,./teardown.sh,./bootstrap-gitea.sh,./teardown-gitea.share kept as forwarding shims, so every existing README reference and shell-history entry still works (with a deprecation note).Formula/pbd.rbinstalls it (brew install --HEAD ./Formula/pbd.rb), with Terraform noted as a caveat since it is BUSL-licensed and out of homebrew-core..github/workflows/ci.ymlruns shellcheck, the 74-case test suite, andbrew style— the same lint-and-test pipeline this tool demands of every app it scaffolds.Not changed
No deploy behavior changes: the command modules are the same code with
SCRIPT_DIRrenamed, the env block lifted out, andmain()renamed to the functionbin/pbdcalls.DIRECTIONS.mdis left as the original design brief.Testing
./test/run.sh: 74 passed, 0 failed — covers dispatch, exit codes, help, version, env-file precedence, symlink resolution, a simulated brew install prefix (and that nothing is written into it), and the deprecated shims.shellcheck -x -S warningclean on all new files; pre-existing warnings in the moved modules unchanged.pbd check --cli bashandpbd teardown --yesexercised end-to-end to their real failure point (missing binary: gh) with correct banner, exit code and transcript path.🤖 Generated with Claude Code
https://claude.ai/code/session_0134vzTxuJJKuRdsu5iyysmz
Generated by Claude Code