Skip to content
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

Add --glob flag to bundle add #7557

Merged

Conversation

thedavemarshall
Copy link
Contributor

@thedavemarshall thedavemarshall commented Apr 4, 2024

Bundler online documentation says that if the gem is located within a subdirectory of a git repository, you can use the :glob option to specify the location of its .gemspec, docs

gem 'cf-copilot', git: 'https://github.com/cloudfoundry/copilot', glob: 'sdk/ruby/*.gemspec'

This change allows for equivalent functionality from the bundler CLI

bundle add cf-copilot --git=https://github.com/cloudfoundry/copilot --glob='sdk/ruby/*.gemspec'

What was the end-user or developer problem that led to this PR?

I'm working on some projects that require gems from remote git sources, and sometimes these projects don't specify the .gemspec file at the root of the repo. Instead of manually editing the Gemfile, I'd like to use bundler's CLI where possible.

What is your fix for the problem, implemented in this PR?

My fix is to pass-through the glob option from Bundler::CLI#add(*gems), to Bundler::Dependency#glob to be used in Bundler::Injector#build_gem_lines()

Make sure the following tasks are checked

Copy link

welcome bot commented Apr 4, 2024

Thanks for opening a pull request and helping make RubyGems and Bundler better! Someone from the RubyGems team will take a look at your pull request shortly and leave any feedback. Please make sure that your pull request has tests for any changes or added functionality.

We use GitHub Actions to test and make sure your change works functionally and uses acceptable conventions, you can review the current progress of GitHub Actions in the PR status window below.

If you have any questions or concerns that you wish to ask, feel free to leave a comment in this PR or join our #rubygems or #bundler channel on Slack.

For more information about contributing to the RubyGems project feel free to review our CONTRIBUTING guide

Copy link
Member

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this option gets a lot of use, but seems nice to have all options mapped to bundle add flags 👍

I think people will need to run this with quotes, otherwise most shells will automatically expand * if run from a directory with gemspecs matching the glob. But there's not much we can do about that. Maybe change tests examples to use quotes, explicitly document it? Not sure.

@thedavemarshall
Copy link
Contributor Author

@deivid-rodriguez good points, thanks for the feedback!

I think people will need to run this with quotes, otherwise most shells will automatically expand * if run from a directory with gemspecs matching the glob. But there's not much we can do about that. Maybe change tests examples to use quotes, explicitly document it? Not sure.

I've changed the specs to use single quotes around the --glob value when invoking bundle add, and I've added banner: text for the CLI explaining that the globs will be expanded with Ruby and recommending single quotes.

@deivid-rodriguez
Copy link
Member

Nice, thanks! This looks good to me! There's a failed spec unrelated to your changes, don't worry about that. I'll merge this next week 👍

Bundler online documentation says that if the gem is located within a subdirectory of a git repository,
you can use the `:glob` option to specify the location of its .gemspec

`gem 'cf-copilot', git: 'https://github.com/cloudfoundry/copilot', glob: 'sdk/ruby/*.gemspec'`

This change allows for equivalent functionality from the bundler CLI

`bundle add cf-copilot --git=https://github.com/cloudfoundry/copilot --glob=sdk/ruby/*.gemspec`
…add banner text for CLI recommending single quotes
@deivid-rodriguez deivid-rodriguez changed the title bundler CLI option for add gem --glob= Add --glob flag to bundle add Apr 12, 2024
Copy link
Member

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@deivid-rodriguez deivid-rodriguez merged commit 153e98a into rubygems:master Apr 12, 2024
83 checks passed
deivid-rodriguez added a commit that referenced this pull request Apr 30, 2024
Add `--glob` flag to `bundle add`

(cherry picked from commit 153e98a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants