Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Add --only parameter to filter files on theme push/theme pull commands #1892

Merged
merged 2 commits into from
Jan 24, 2022

Conversation

karreiro
Copy link
Contributor

@karreiro karreiro commented Jan 5, 2022

WHY are these changes introduced?

Currently, users can't filter files when they execute theme pull (#1558) or theme push. This PR introduces a new -o/--only parameter to take care of that.

WHAT is this pull request doing?

This PR introduces the ShopifyCLI::Theme::IncludeFilter class, which behaves similarly to the ShopifyCLI::Theme::IgnoreFilter, but includes files that match with the query instead of excluding them.

How to test your changes?

Run the following commands for testing the new --only parameter and notice that all files will be ignored, except the ones in the templates directory:

~$ DEBUG=1 shopify-dev theme pull -t THEME_NAME --only "templates/*"
~$ DEBUG=1 shopify-dev theme push -t THEME_NAME --only "templates/*"

pull-only

Post-release steps

Update documentation with the new -o/--only=PATTERN parameter: https://shopify.dev/themes/tools/cli/theme-commands#push, https://shopify.dev/themes/tools/cli/theme-commands#pull.

Update checklist

  • I've added a CHANGELOG entry for this PR (if the change is public-facing)
  • I've considered possible cross-platform impacts (Mac, Linux, Windows).
  • I've left the version number as is (we'll handle incrementing this when releasing).
  • I've included any post-release steps in the section above.

@karreiro karreiro linked an issue Jan 5, 2022 that may be closed by this pull request
@karreiro
Copy link
Contributor Author

👋 Hello, @MeredithCastile! :)

In many command-line tools, the flag -if stands for --force to perform some operation without confirmation.

To avoid using -f for the filter (so, we may have something like shopify theme push --force in the future), I've adopted the -q/--query in this PR.

Still, I'm not entirely sure it's a good idea 😅 What do you think about this?

Thanks a lot!

@MeredithCastile
Copy link
Contributor

Hmm, I'm not sure. Filter seems more intuitive and comprehensible to me than query.

One thing your questions have raised for me, @karreiro, is whether or not we need a shortcut/alias for every flag. If we support only full words for rarer flag, then we could have more than one starting with the same letter.

@pedropinerashopify, curious if you agree with the idea that every flag does NOT need a one-letter shortcut?

@karreiro
Copy link
Contributor Author

karreiro commented Jan 14, 2022

(cc @pepicrft)

Generally, when I'm using command-line tools, I usually use the shortcuts, and when the commands get too lengthy, I tend to create aliases for them (but this is a total personal use/opinion).

@pepicrft
Copy link
Contributor

pepicrft commented Jan 18, 2022

I agree that --force/-f is extensively used across CLIs to mean "force" and I'd refrain from using it for querying. Note that there's the option to have lower and upper-cased aliases so we could go with something like:

--force / -f
--filter / -F

I've seen CLIs doing that as a way to disambiguate and I think it's something we can adopt here too.

@karreiro
Copy link
Contributor Author

karreiro commented Jan 18, 2022

🤯 --filter, -F seems like an excellent approach! Thanks for that idea, @pepicrft!

@karreiro karreiro marked this pull request as ready for review January 19, 2022 12:34
@karreiro karreiro requested review from a team, jesalerno84, gonzaloriestra and macournoyer and removed request for a team January 19, 2022 12:34
@karreiro karreiro changed the title Add --query parameter to filter files on theme push/theme pull commands Add --filter parameter to filter files on theme push/theme pull commands Jan 19, 2022
@MeredithCastile
Copy link
Contributor

MeredithCastile commented Jan 19, 2022

Ah, that's such an interesting idea, @pepicrft. So then I suppose there are 2 possibilities (unless we widen the scope of this issue):

POSSIBILITY 1: case-sensitive shortcuts

--force / -f
--filter / -F

Pro: More intuitive language
Con: People are going to inevitably try to filter and accidentally force

POSSIBILITY 2: just go with query

--query / -q

Pro: No risk of the "user error" stated above
Con: Less intuitive command

__

I don't know how disruptive an accidental force command would be, so I'm not well-positioned to weigh between these options.

@macournoyer
Copy link
Contributor

Just throwing another option out (sorry 😄)

What about -o / --only [PATTERN]. Seems clearer to me that it will filter to only include those files. Where --filter makes me think of "filter out", this reads better to me:

shopify theme pull --only *.js

@karreiro
Copy link
Contributor Author

No reason to be sorry! This approach is awesome :) It makes the command much more expressive!

Thanks a lot, @macournoyer 🚀

PS.: I believe we may keep case-sensitive shortcuts in mind for future scenarios, but for this PR, I believe the --only offers the best DX :)

@karreiro karreiro changed the title Add --filter parameter to filter files on theme push/theme pull commands Add --only parameter to filter files on theme push/theme pull commands Jan 21, 2022
@MeredithCastile
Copy link
Contributor

@macournoyer Such an elegant solution! Thank you!

@karreiro karreiro merged commit f017613 into main Jan 24, 2022
@karreiro karreiro deleted the fix-1558 branch January 24, 2022 08:54
@jibinycricket
Copy link

jibinycricket commented Jan 28, 2022

Is there a way to pass multiple --only paramaters similar to --ignore?

shopify theme pull -d -n -o 'templates/*.json' -o 'config/settings_data.json'

Right now it only pulls the last only option which is config/settings_data.json

@blanklob
Copy link
Contributor

Is there a way to pass multiple --only paramaters similar to --ignore?

shopify theme pull -d -n -o 'templates/*.json' -o 'config/settings_data.json'

Right now it only pulls the last only option which is config/settings_data.json

@jibinycricket You can use the command shopify theme pull -d -n --only "**/*.json"

kilgore5 pushed a commit to kilgore5/shopify-cli that referenced this pull request Feb 1, 2022
@kilgore5
Copy link
Contributor

kilgore5 commented Feb 2, 2022

PR addressing #1892 (comment).... #2002

kilgore5 pushed a commit to kilgore5/shopify-cli that referenced this pull request Feb 9, 2022
These updates fix an issue where a local `package.json` file was being deleted despite being in the `.shopifyignore` file.

- update `download_file!` method to use similar "ignore" handling as the `enqueue` method... using `ignore?` method added in Shopify#1892
- extract `ignore_path?` method from `ignore?` method so it can be called separately from an operation
- update `ignore_path?` to check for a File object and extract the path from that
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to filter files on pull
7 participants