From 78adf4d5c77415e1a7ee6256da3bf2ebfaee76ed Mon Sep 17 00:00:00 2001 From: John Britton Date: Tue, 15 Dec 2020 21:19:06 -0500 Subject: [PATCH] alternative approach --- lib/bundle/commands/add.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/bundle/commands/add.rb b/lib/bundle/commands/add.rb index ffd96d524..063d63823 100644 --- a/lib/bundle/commands/add.rb +++ b/lib/bundle/commands/add.rb @@ -12,20 +12,20 @@ def run(*args, global: false, file: nil) name = args.first # only support one formula at a time for now options = {} # we don't currently support passing options - # read the relevant Brewfile - parsed_entries = Bundle::Dsl.new(Brewfile.read(global: global, file: file)).entries + # parse the relevant Brewfile + dsl = Bundle::Dsl.new(Brewfile.read(global: global, file: file)) # check each of the entries in the specified Brewfile - parsed_entries.each do |entry| + dsl.entries.each do |entry| # raise an error if the entry already exists in the Brewfile # this could also be a noop, or print a friendly message opoo "'#{name}' already exists in Brewfile." raise RuntimeError if entry.name == name end - # 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? + dsl.brew(name, options) + # execute brew bundle + # execute brew bundle dump end end end