Skip to content

fix: validate init template flags before the non-empty-directory prompt #149

Description

@Bccorb

Problem

seamless init --bogus in a non-empty directory asks the destructive overwrite question
before it ever discovers the flag is unknown.

The order in src/commands/init.ts is:

  1. scaffold() reads the directory and, when it is not empty, calls
    chooseExistingDirectoryAction() (src/prompts/initMode.ts),
    which prompts "Scaffold a project here anyway? Starter files overwrite anything with the
    same name."
  2. Only after that does scaffoldLocal() / scaffoldManaged() call
    resolveTemplateAliases(), which is what throws Unknown option "--bogus".

So a typo, or the documented "run an unknown flag to see the available examples" hint, both
route a developer through an overwrite prompt on the way to an error. The default is No and
it requires explicit confirmation, which is what keeps this from being a data-loss bug, but
the common scripted pattern of piping y at the first prompt turns it into one.

PR #148 fixed the worst instance of this (--help / -h are now handled ahead of every
command's own parsing), but any other unrecognized flag still takes the same path.

Change

  • Resolve and validate template flags in runCLI() before scaffold() touches the
    filesystem, so an unknown or conflicting flag exits non-zero with the available flags
    listed and nothing is prompted.
  • Keep the existing error text from resolveTemplateAliases(); only the timing moves.
  • Drop the "Run an unknown flag to see the available examples" line from the init help body
    in src/commands/helpTopics.ts. Discovery belongs in
    seamless templates list (separate issue), not in an error path.

Acceptance

  • seamless init --bogus in a directory full of files errors immediately, prompts nothing,
    and exits non-zero.
  • Conflicting flags (two web templates) behave the same way.
  • A valid flag still reaches the existing-directory prompt exactly as it does today.
  • Unit test covering "unknown flag in a non-empty directory never calls the prompt".

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:cliSeamless CLIbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions