Add infrastructure for required non-interactive flags - #8207
Open
gonzaloriestra wants to merge 2 commits into
Open
Add infrastructure for required non-interactive flags#8207gonzaloriestra wants to merge 2 commits into
gonzaloriestra wants to merge 2 commits into
Conversation
Contributor
Author
|
/snapit |
Contributor
|
🫰✨ Thanks @gonzaloriestra! Your snapshot has been published to npm. Test the snapshot by installing your package globally: pnpm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20260731093434Caution After installing, validate the version by running |
gonzaloriestra
force-pushed
the
gonzalo/noninteractive-required-flags
branch
from
July 31, 2026 10:32
62cc62e to
40d5db8
Compare
This was referenced Jul 31, 2026
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
gonzaloriestra
force-pushed
the
gonzalo/noninteractive-required-flags
branch
from
July 31, 2026 12:29
40d5db8 to
9daf6ea
Compare
gonzaloriestra
marked this pull request as ready for review
July 31, 2026 14:09
gonzaloriestra
force-pushed
the
gonzalo/noninteractive-required-flags
branch
from
July 31, 2026 14:15
9daf6ea to
415b7bb
Compare
Contributor
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/public/node/base-command.d.ts@@ -2,8 +2,15 @@ import { Command } from '@oclif/core';
import { OutputFlags, Input, ParserOutput, FlagInput, OutputArgs } from '@oclif/core/parser';
export type ArgOutput = OutputArgs<any>;
export type FlagOutput = OutputFlags<any>;
+export interface NonTTYFlagRequirement {
+ /** At least one of these flags must be present when the requirement applies. */
+ flags: string[];
+ /** Determines whether the requirement applies to the parsed flags. */
+ when?: (flags: FlagOutput) => boolean;
+}
declare abstract class BaseCommand extends Command {
static baseFlags: FlagInput<{}>;
+ static nonTTYFlagRequirements(_flags: FlagOutput): NonTTYFlagRequirement[];
static descriptionWithoutMarkdown(): string | undefined;
static analyticsNameOverride(): string | undefined;
static analyticsStopCommand(): string | undefined;
@@ -22,6 +29,8 @@ declare abstract class BaseCommand extends Command {
}>;
protected environmentsFilename(): string | undefined;
protected failMissingNonTTYFlags(flags: FlagOutput, requiredFlags: string[]): void;
+ private failMissingNonTTYFlagRequirements;
+ private applicableNonTTYFlagRequirements;
private resultWithEnvironment;
/**
* Tries to load an environment to forward to the command. If no environment
packages/cli-kit/dist/public/node/cli.d.ts@@ -55,6 +55,19 @@ export declare const portFlag: (options?: {
env?: string;
hidden?: boolean;
}) => import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
+/**
+ * Marks a flag as required when the CLI cannot prompt for a value.
+ *
+ * The flag remains optional in interactive terminals. In non-interactive environments,
+ * `BaseCommand` validates the flag automatically and the requirement is shown in `--help`.
+ * Use `BaseCommand.nonTTYFlagRequirements` for conditional or alternative requirements.
+ *
+ * @param flag - An oclif flag definition.
+ * @returns A new flag definition annotated for non-interactive validation and help output.
+ */
+export declare function requiredIfNonInteractive<TFlag extends {
+ description?: string;
+}>(flag: TFlag): TFlag;
/**
* Clear the CLI cache, used to store some API responses and handle notifications status
*/
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Related: https://github.com/shop/issues-develop/issues/22928
Summary
requiredIfNonInteractiveflag metadata and appendRequired if non interactiveto help descriptions.BaseCommand.Context
This builds on the approach explored in #7716 by @nickwesselman: annotate flags at definition time and validate them centrally in
BaseCommand. It completes the infrastructure with grouped and conditional requirements plus aggregated errors.This PR only prepares the infrastructure. Command adoption follows in the dependent PRs for apps, themes, stores, and other commands.
Testing
See #8223