| … | … | @@ -107,6 +107,9 @@ export async function run (argv) { |
| 107 | 107 | return |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | // Past the help check, `--` has done its job — hand commands the values. |
| 111 | const cmdArgs = stripOptionTerminator(command, args) |
| 112 | |
| 110 | 113 | const appName = globals.app || DEFAULT_APP |
| 111 | 114 | let client = null |
| 112 | 115 | if (NEEDS_DAEMON.has(command)) { |
| … | … | @@ -119,7 +122,7 @@ export async function run (argv) { |
| 119 | 122 | } |
| 120 | 123 | |
| 121 | 124 | try { |
| 122 | | const result = await mod.run(client, args, globals) |
| 125 | const result = await mod.run(client, cmdArgs, globals) |
| 123 | 126 | if (result !== undefined && result !== null) { |
| 124 | 127 | console.log(formatOutput(result, globals.format)) |
| 125 | 128 | } |
| … | … | @@ -139,7 +142,26 @@ export async function run (argv) { |
| 139 | 142 | export function wantsHelp (command, args) { |
| 140 | 143 | if (args[0] === 'help' || args[0] === '--help' || args[0] === '-h') return true |
| 141 | 144 | 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 | */ |
| 161 | export 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)) |
| 143 | 165 | } |
| 144 | 166 | |
| 145 | 167 | function printCommandUsage (command, mod) { |