-
Notifications
You must be signed in to change notification settings - Fork 202
Ensure user provided flag values override defaults in multi env commands #6301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Coverage report
Show files with reduced coverage 🔻
Test suite run success3239 tests passing in 1354 suites. Report generated by 🧪jest coverage report action from cb170bd |
/snapit |
6517d05
to
f4752a1
Compare
const {flags: flagsWithoutDefaults} = await this.parse(noDefaultsOptions(klass), this.argv) | ||
if ('path' in flagsWithoutDefaults) { | ||
renderWarning({ | ||
body: "Provide each environment's command path in your shopify.theme.toml file.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking out loud: what if I'm in ~
and I run shopify theme command -e 1 -e2 --path ~/path/to/shopify.theme.toml
? I think that's probably the most common use case of including --path
so we could potentially change the language of the warning maybe? Some pseudo code here:
if ('path' in flagsWithoutDefaults) {
if (flagsWithoutDefaults.path === cwd()) {
renderError({body: "Something about needing to run it in the same directory as the toml"});
return;
}
renderError({body: "Cannot use the `--path` flag with multiple environments. Provide each environment's command path in your shopify.theme.toml file."});
return
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And maybe use renderError
since we can't continue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, thanks! I updated the message
42edc3e
to
9ebe9e1
Compare
/snapit |
🫰✨ Thanks @dejmedus! Your snapshot has been published to npm. Test the snapshot by installing your package globally: pnpm i -g @shopify/[email protected] Tip If you get an Caution After installing, validate the version by running just |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎩 went great! Just need a small amount of test coverage and we'll be good to go!
if ('path' in flagsWithoutDefaults) { | ||
this.errorOnGlobalPath() | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make sure we add a couple of tests for the two error scenarios
9ebe9e1
to
6dcea1d
Compare
Previously, default flag values were treated by multi environment command mapping as CLI values, which take precedence over .toml values. This commit ensures that flag values are selected in order: 1. User provided CLI args 2. User provided shopify.theme.toml values 3. Default flag values
The path flag should point to where a command will be run. This defaults to the current working directory While running a command with multiple environment flags, providing a path via the CLI will take precedence over toml and default values and try to run every environment at the same path. This PR prevents this by displaying a warning message
6dcea1d
to
cb170bd
Compare
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@@ -32,4 +32,17 @@ export declare function addFromParsedFlags(flags: {
path?: string;
verbose?: boolean;
}): Promise<void>;
+/**
+ * Strips the defaults from configured flags. For example, if flags contains:
+ *
+ *
+ *
+ * it becomes:
+ *
+ *
+ *
+ * If we parse using this configuration, the only specified flags will be those
+ * the user actually passed on the command line.
+ */
+export declare function noDefaultsOptions<TFlags extends FlagOutput, TGlobalFlags extends FlagOutput, TArgs extends ArgOutput>(options: Input<TFlags, TGlobalFlags, TArgs> | undefined): Input<TFlags, TGlobalFlags, TArgs> | undefined;
export default BaseCommand;
\ No newline at end of file
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎩 went well. Thanks for the changes!
WHY are these changes introduced?
Previously, default flag values were treated by multi environment command mapping as CLI values, which take precedence over shopify.theme.toml values. This PR ensures that flag values are selected in order:
WHAT is this pull request doing?
--path
flag is provided to the CLI during multi env runs (path defaults tocwd
and should be set per environment inshopify.theme.toml
)shopify.theme.toml is respected over default values
defaults-demo.mov
path warning
How to test your changes?
shopify.theme.toml
file with a value that has a default likejson = true
Example toml
gh pr checkout 6301
or install the snapit versionlist
and you should see that the environments withjson = true
defined in the .toml print out json and other environments don't--path
flag with multi env commands should display an errorMeasuring impact
Checklist