Skip to content

fix(create-indiekit): handle command-line arguments - #909

Open
rmdes wants to merge 1 commit into
mainfrom
fix/create-indiekit-argv
Open

fix(create-indiekit): handle command-line arguments#909
rmdes wants to merge 1 commit into
mainfrom
fix/create-indiekit-argv

Conversation

@rmdes

@rmdes rmdes commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

Fixes #908.

create-indiekit never read process.argv, so --help and --version fell through to the setup questions, and an unrecognised option became the name of the scaffolded directory — base-create takes process.argv[2] verbatim.

What this changes

  • lib/cli.js (new) parses arguments with parseArgs from node:util. --help/--version print and exit 0; an unrecognised option is named and exits 1.
  • A missing directory is reported before any question is asked. base-create already requires one, but only checks after the last answer, so those answers were thrown away.
  • bin/create.js checks for an interactive terminal before prompting. Without one, prompts never settles and Node reported an unsettled top-level await; it now says what's wrong and exits 1.
  • index.js passes onCancel to prompts. Cancelling resolved with whatever had been answered so far, so a cancelled run carried on and scaffolded with empty answers. It now throws, and bin/create.js turns that into a clean exit 1.

Notes on the approach

Parsed non-strictly, so an unrecognised option is reported by name rather than throwing. Under strict: true, parseArgs throws on anything unknown, which would turn a currently-harmless stray option into a crash.

I used parseArgs rather than commander to avoid adding a dependency — the package already imports from node:util, and this needs two booleans and one positional. packages/indiekit uses commander for its CLI, so say the word if you'd rather the two binaries matched and I'll switch.

Cancellation is signalled with an error.code of ERR_SETUP_CANCELLED rather than calling process.exit() in index.js, since unicorn/no-process-exit restricts that to the binary.

Verification

packages/create-indiekit unit tests: 23 pass, 0 fail (9 new, in test/unit/cli.js). eslint and prettier clean.

$ node bin/create.js --help          # usage, exit 0
$ node bin/create.js --version       # 1.0.0-beta.29, exit 0
$ node bin/create.js --foo           # Unknown option: --foo, exit 1
$ node bin/create.js                 # Provide a directory. exit 1
$ node bin/create.js myproject       # (no TTY) This command needs an interactive terminal. exit 1

No directory named --help is created in any of those.

Not addressed here

Two inconsistencies noted in #908 that felt out of scope for this change: engines.node is >=24.17 while the runtime guard in bin/create.js only rejects Node < 20, and docs/get-started.md documents the directory as optional though base-create requires it. Happy to fold either in.

`create-indiekit` never read `process.argv`, so:

- `--help` and `--version` fell through to the setup questions
- an unrecognised option became the name of the scaffolded directory,
  since `base-create` takes `process.argv[2]` verbatim
- a missing directory was only reported once every question had been
  answered, throwing those answers away
- without a terminal, `prompts` never settled, so Node reported an
  unsettled top-level await rather than anything actionable

Parse arguments with `parseArgs` from `node:util`, non-strictly so that an
unrecognised option is reported by name rather than throwing, and check for
an interactive terminal before asking anything.

Also pass `onCancel` to `prompts`. Cancelling resolved with whatever had
been answered so far, so a cancelled run carried on and scaffolded using
empty answers.
@rmdes
rmdes force-pushed the fix/create-indiekit-argv branch from a6e3fb3 to e76c45f Compare August 23, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create-indiekit ignores CLI arguments: --help becomes the project directory, and cancelling scaffolds with empty answers

1 participant