66// give instant feedback before Node launches.
77//
88// What the injected bash does (inside the else block, before the "$NODE ... $DIR/run" line):
9- // - codify --help / -h → cats dist/static/help.txt and exits (no Node startup)
10- // - codify --version / -v → cats dist/static/version.txt and exits
11- // - codify apply/destroy/plan → prints "Running Codify <cmd>..." immediately
12- // (suppressed when --output json or -o json is passed)
13- // - everything else → falls through to normal Node.js launch
9+ // - codify --help / -h → cats dist/static/help.txt and exits (no Node startup)
10+ // - codify <cmd> --help / -h → cats dist/static/<cmd>-help.txt and exits
11+ // - codify --version / -v → cats dist/static/version.txt and exits
12+ // - codify apply/destroy/plan → prints "Running Codify <cmd>..." immediately
13+ // (suppressed when --output json or -o json is passed)
14+ // - everything else → falls through to normal Node.js launch
1415//
15- // Static files (dist/static/help.txt, dist/static/version.txt) are generated in scripts/pkg.ts
16- // after the esbuild step by running ./bin/dev.js --help and ./bin/dev.js --version.
16+ // Static files (dist/static/*.txt) are generated in scripts/pkg.ts after the esbuild step.
1717// Missing static files are guarded by [ -f ] so all cases fall back to Node gracefully.
1818//
1919// Note: console.log('Running Codify apply/destroy...') was removed from src/commands/apply.ts
@@ -34,11 +34,11 @@ if (!existsSync(BIN_JS)) {
3434 process . exit ( 0 ) ;
3535}
3636
37- const content = await fs . readFile ( BIN_JS , 'utf8' ) ;
37+ let content = await fs . readFile ( BIN_JS , 'utf8' ) ;
3838
3939if ( content . includes ( 'CODIFY_PATCH_START' ) ) {
40- console . log ( 'oclif bin.js already patched. Skipping .' ) ;
41- process . exit ( 0 ) ;
40+ console . log ( 'Removing existing patch to reapply.. .' ) ;
41+ content = content . replace ( / # C O D I F Y _ P A T C H _ S T A R T [ \s \S ] * ? # C O D I F Y _ P A T C H _ E N D [ ^ \n ] * \n / , '' ) ;
4242}
4343
4444const SEARCH = ' if [ "\\$DEBUG" == "*" ]; then\n echoerr' ;
@@ -49,14 +49,21 @@ if (idx === -1) {
4949}
5050
5151// Patch uses \\$ so that it survives the JS string — in the generated shell script each \\$ becomes \$
52- // which Bash then interprets as a literal $ (not a template substitution in the JS template literal).
52+ // which bash then interprets as a literal $ (not a template substitution in the JS template literal).
53+ // Bash default-value syntax ${1:-} is avoided since ${...} would be evaluated as a JS template expression.
5354const PATCH = ` # CODIFY_PATCH_START — do not remove this marker
5455 _first_arg=""
5556 if [ "\\$#" -gt 0 ]; then _first_arg="\\$1"; fi
57+ _second_arg=""
58+ if [ "\\$#" -gt 1 ]; then _second_arg="\\$2"; fi
5659 if [ "\\$_first_arg" = "--help" ] || [ "\\$_first_arg" = "-h" ]; then
5760 _help_file="\\$DIR/../dist/static/help.txt"
5861 if [ -f "\\$_help_file" ]; then cat "\\$_help_file"; exit 0; fi
5962 fi
63+ if [ "\\$_second_arg" = "--help" ] || [ "\\$_second_arg" = "-h" ]; then
64+ _cmd_help_file="\\$DIR/../dist/static/\\$_first_arg-help.txt"
65+ if [ -f "\\$_cmd_help_file" ]; then cat "\\$_cmd_help_file"; exit 0; fi
66+ fi
6067 if [ "\\$_first_arg" = "--version" ] || [ "\\$_first_arg" = "-v" ] || [ "\\$_first_arg" = "version" ]; then
6168 _version_file="\\$DIR/../dist/static/version.txt"
6269 if [ -f "\\$_version_file" ]; then cat "\\$_version_file"; exit 0; fi
0 commit comments