OverviewFilesCommitsIssuesDocsReleasesPeers

pgh commits / 993bd9c

0.1.134: honour `--` as an end-of-options separator
There was no way to name a thing that looks like a flag. wantsHelp() returned true for `--help` ANYWHERE in args, so `pgh repo retire --help` printed usage instead of retiring — and the forge really does contain a repo called `--help`, created back when an issues read minted repos. It had to be tombstoned through a direct UDS call because the CLI could not express it. `--help` meaning "show me help for retire" is the RIGHT default and is kept. What was missing is the POSIX escape hatch: pgh repo retire --help → usage for retire (unchanged) pgh repo retire -- --help → retires the repo named --help wantsHelp now only considers tokens BEFORE the first `--`, and stripOptionTerminator removes that separator before the command runs, so subcommands receive the real values. Previously `--` was forwarded verbatim and became the repo name, so `retire -- --help` tried to retire a repo called `--`. Passthrough commands are exempt: they forward argv to git, where `--` is meaningful (`git checkout -- <path>`) and must survive. Verified `pgh push origin -- --help` keeps its separator while `pgh repo retire -- --help` loses it. Caught a would-be runtime bug in the same change: `args` is destructured with const at the dispatch site, so assigning the stripped value back to it would have thrown on every command. Bound to a separate `cmdArgs` instead. `node --check` did not flag it — only reading the surrounding lines did. Verified across 7 cases: help detection, the escape hatch, plain args, leading -h, and passthrough with and without a separator. Note the sibling gap this leaves: `pgh repo unretire --help` needs the same `--` form, which now works. But the CLI still cannot express a repo whose name IS `--` — that one stays a UDS call, and nothing on the fleet is named that. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
993bd9cdf6b26441efa91a8e1f701443840af5ec
by plankatron <fleeky@gmail.com> · 2026-07-31T00:05:01.000Z

Changed files (2) +25 -3

lib/cli.js +24 -2
……@@ -107,6 +107,9 @@ export async function run (argv) {
107107 return
108108 }
109109
110 // Past the help check, `--` has done its job — hand commands the values.
111 const cmdArgs = stripOptionTerminator(command, args)
112
110113 const appName = globals.app || DEFAULT_APP
111114 let client = null
112115 if (NEEDS_DAEMON.has(command)) {
……@@ -119,7 +122,7 @@ export async function run (argv) {
119122 }
120123
121124 try {
122 const result = await mod.run(client, args, globals)
125 const result = await mod.run(client, cmdArgs, globals)
123126 if (result !== undefined && result !== null) {
124127 console.log(formatOutput(result, globals.format))
125128 }
……@@ -139,7 +142,26 @@ export async function run (argv) {
139142export function wantsHelp (command, args) {
140143 if (args[0] === 'help' || args[0] === '--help' || args[0] === '-h') return true
141144 if (PASSTHROUGH.has(command)) return false
142 return args.includes('--help') || args.includes('-h')
145 // `--` ends option parsing (POSIX convention): everything after it is a
146 // VALUE, never a flag. Without this there is no way to name a thing that
147 // looks like a flag — and the forge really does contain a repo called
148 // `--help`, created back when a read minted repos. `pgh repo retire --help`
149 // rightly prints usage; `pgh repo retire -- --help` retires that repo.
150 const end = args.indexOf('--')
151 const flagArgs = end === -1 ? args : args.slice(0, end)
152 return flagArgs.includes('--help') || flagArgs.includes('-h')
153}
154
155/**
156 * Drop the first standalone `--` so commands receive the real values.
157 *
158 * NOT applied to passthrough commands: those forward argv to git, where `--`
159 * is meaningful (`git checkout -- <path>`) and must survive untouched.
160 */
161export function stripOptionTerminator (command, args) {
162 if (PASSTHROUGH.has(command)) return args
163 const i = args.indexOf('--')
164 return i === -1 ? args : args.slice(0, i).concat(args.slice(i + 1))
143165}
144166
145167function printCommandUsage (command, mod) {
package.json +1 -1
……@@ -1,6 +1,6 @@
11{
22 "name": "pgh",
3 "version": "0.1.133",
3 "version": "0.1.134",
44 "description": "pgh — P2P content-addressed package manager and app launcher",
55 "type": "module",
66 "main": "index.js",