Skip to content

Add requiredIfNonInteractive flag factory and apply to app init --template#7716

Draft
nickwesselman wants to merge 1 commit into
Shopify:mainfrom
nickwesselman:required-if-non-interactive
Draft

Add requiredIfNonInteractive flag factory and apply to app init --template#7716
nickwesselman wants to merge 1 commit into
Shopify:mainfrom
nickwesselman:required-if-non-interactive

Conversation

@nickwesselman
Copy link
Copy Markdown
Contributor

@nickwesselman nickwesselman commented Jun 4, 2026

WHY are these changes introduced?

Related to https://github.com/shop/issues-develop/issues/22928

Some flags shouldn't be strictly required (the command can prompt for them in an interactive session), but they must be supplied when the CLI runs non-interactively (CI, or piped input). Today BaseCommand already has failMissingNonTTYFlags(), but each command has to pass a hardcoded list of flag names, and there's no way to surface the requirement in --help.

WHAT is this pull request doing?

Introduces a requiredIfNonInteractive flag factory in cli-kit and wires it into the base command, and applies it to app init --template as the first usage.

Design note

The custom requiredIfNonInteractive property is read from the live command class at parse time, because it is stripped from the cached oclif manifest (cacheFlags only copies an allowlist of known properties). The help annotation instead lives in description — a cached field — so it survives manifest generation. This is why the manifest diff shows the new description but not the custom property.

How to test your changes?

In a non-interactive shell (no TTY / CI):

$ shopify app init --path /tmp/new-app
#  ✖ Flag not specified: template
#    This flag is required in non-interactive terminal environments...

shopify app init --help shows:

--template=<value>
    (required if non-interactive) The app template. Accepts one of the following:
    ...

In an interactive terminal, app init still prompts for the template as before.

Measuring impact

  • No impact on usage metrics

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if changes are user-facing
  • I've added a test to cover my changes, if needed

🤖 Generated with Claude Code

…mplate`

Introduce a `requiredIfNonInteractive` flag factory in cli-kit that marks a
flag as required when running in a non-interactive terminal (CI, piped input),
while keeping it optional in interactive sessions where the command can prompt.

- The factory tags the flag with a custom `requiredIfNonInteractive` property
  and prepends "(required if non-interactive)" to its description, mirroring
  oclif's "(required)" rendering.
- BaseCommand.parse() auto-collects flags carrying the marker from the live
  command class and routes them through the existing failMissingNonTTYFlags
  helper, so every command gets the behavior without a hardcoded list.
- Apply it to `app init --template` as the first usage.

The custom property is read from the live command class at parse time, since
it is stripped from the cached oclif manifest. The help annotation lives in
`description` (a cached field) so it survives manifest generation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant