-
-
Notifications
You must be signed in to change notification settings - Fork 290
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
Create add
and remove
subcommands for brew bundle
#832
Create add
and remove
subcommands for brew bundle
#832
Conversation
type = :brew # default to brew | ||
name = args.first # only support one formula at a time for now | ||
options = {} # we don't currently support passing options |
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.
Should we handle different types of formulae? Is there an existing pattern for how you'd like this handled?
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.
I think it's fine to just support brew
for now and people can extend it later if desired. As long as it's documented it can raise UsageError
which will print the help text.
lib/bundle/commands/add.rb
Outdated
# need some help / pointers here | ||
# is it possible to use Bundle::Dsl to create an in memory representation | ||
#of the brewfile that we read, add an entry and then dump that back to the 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.
This is where I could use the most help
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.
This is the existing dumper code for this:
homebrew-bundle/lib/bundle/brew_dumper.rb
Lines 18 to 39 in 034459d
def formulae | |
@formulae ||= begin | |
@formulae = formulae_info | |
sort! | |
end | |
end | |
def dump(describe: false, no_restart: false) | |
requested_formula = formulae.select do |f| | |
f[:installed_on_request?] || !f[:installed_as_dependency?] | |
end | |
requested_formula.map do |f| | |
brewline = "" | |
brewline += desc_comment(f[:desc]) if describe && f[:desc] | |
brewline += "brew \"#{f[:full_name]}\"" | |
args = f[:args].map { |arg| "\"#{arg}\"" }.sort.join(", ") | |
brewline += ", args: [#{args}]" unless f[:args].empty? | |
brewline += ", restart_service: true" if !no_restart && BrewServices.started?(f[:full_name]) | |
brewline += ", link: #{f[:link?]}" unless f[:link?].nil? | |
brewline | |
end.join("\n") | |
end |
It's probably possible to do that but you may have more luck trying to inject your desired formulae state into the existing logic (overriding @formulae
somehow).
From my vague recollection, I can't remember anywhere that
It looks like other parts of the ecosystem are moving to flags which seem suitable to use here too. For example |
Actually, I lie. There is homebrew-bundle/lib/bundle/commands/list.rb Lines 11 to 15 in 034459d
|
I think we need to handle the case where there are options to add. From a fresh brew "paulp/extras/coursier", args: ["HEAD"]
brew "sshfs", link: false
brew "neovim", args: ["HEAD"]
brew "md5sha1sum", link: false Will this also support adding a tap to the Brewfile, perhaps with --tap? |
type = :brew # default to brew | ||
name = args.first # only support one formula at a time for now | ||
options = {} # we don't currently support passing options |
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.
I think it's fine to just support brew
for now and people can extend it later if desired. As long as it's documented it can raise UsageError
which will print the help text.
lib/bundle/commands/add.rb
Outdated
# this could also be a noop, or print a friendly message | ||
raise RuntimeError if entry.name == name |
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.
Yup, friendly message would be nice.
lib/bundle/commands/add.rb
Outdated
# need some help / pointers here | ||
# is it possible to use Bundle::Dsl to create an in memory representation | ||
#of the brewfile that we read, add an entry and then dump that back to the 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.
This is the existing dumper code for this:
homebrew-bundle/lib/bundle/brew_dumper.rb
Lines 18 to 39 in 034459d
def formulae | |
@formulae ||= begin | |
@formulae = formulae_info | |
sort! | |
end | |
end | |
def dump(describe: false, no_restart: false) | |
requested_formula = formulae.select do |f| | |
f[:installed_on_request?] || !f[:installed_as_dependency?] | |
end | |
requested_formula.map do |f| | |
brewline = "" | |
brewline += desc_comment(f[:desc]) if describe && f[:desc] | |
brewline += "brew \"#{f[:full_name]}\"" | |
args = f[:args].map { |arg| "\"#{arg}\"" }.sort.join(", ") | |
brewline += ", args: [#{args}]" unless f[:args].empty? | |
brewline += ", restart_service: true" if !no_restart && BrewServices.started?(f[:full_name]) | |
brewline += ", link: #{f[:link?]}" unless f[:link?].nil? | |
brewline | |
end.join("\n") | |
end |
It's probably possible to do that but you may have more luck trying to inject your desired formulae state into the existing logic (overriding @formulae
somehow).
I can't figure out a way to write out a Would it be reasonable for homebrew-bundle/lib/bundle/commands/add.rb Lines 15 to 28 in 78adf4d
I had originally planned to keep updating the I'm open to other ideas / suggestions if anyone has opinions. |
I think the main issue I'd see with this is if the user has other things that are installed that would also be dumped to the Brewfile.
Yup. Something I said in #818:
How about something like that? |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
As discussed in #818
Add two subcommands
brew bundle add
andbrew bundle remove
which will add or remove a specified formula to theBrewfile
. When the--global
option is specified the formula is added or removed from the globalBrewfile
I've figured out how to add new subcommands and also figured out how to read in the
Brewfile
and check if the requested formula is already in theBrewfile
.I'm looking for suggestions on how to add to the
Brewfile
and write it out to disk. My hope is that there is some in memory way to manipulate the Brewfile and call dump. I looked atBundle::Dumper
but that seems to operate based on what's installed on the system, not what was parsed from theBrewfile
.Additionally, looking for feedback on the command line syntax for how we should handle formulae that are not
:brew
but are:cask
,:tap
,:mas
, or any other type. For examplebrew bundle add cask atom
.