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

Create add and remove subcommands for brew bundle #832

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ def bundle
zap: args.zap?,
)
end
when "add"
Bundle::Commands::Add.run(
global: args.global?,
file: args.file,
)
when "dump"
Bundle::Commands::Dump.run(
global: args.global?,
Expand Down
32 changes: 32 additions & 0 deletions lib/bundle/commands/add.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

module Bundle
module Commands
module Add
module_function

def run(*args, global: false, file: nil)
raise UsageError, "No arguments were specified!" if args.blank?

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
Comment on lines +11 to +13
Copy link
Member Author

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?

Copy link
Member

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.


# parse the relevant Brewfile
dsl = Bundle::Dsl.new(Brewfile.read(global: global, file: file))

# check each of the entries in the specified Brewfile
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

dsl.brew(name, options)
# execute brew bundle
# execute brew bundle dump
end
end
end
end
45 changes: 45 additions & 0 deletions spec/bundle/commands/add_command_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

require "spec_helper"

describe Bundle::Commands::Add do
context "when a Brewfile is not found" do
it "raises an error" do
expect { described_class.run("wget") }.to raise_error(RuntimeError)
end
end

context "when a Brewfile is found" do
before do
allow_any_instance_of(Pathname).to receive(:read)
.and_return("brew 'openssl'")
end

context "when no arguments are passed" do
it "raises an error" do
expect { described_class.run }.to raise_error(UsageError)
end
end

context "the formula is not in the Brewfile" do
it "does not raise an error" do
expect { described_class.run("wget") }.not_to raise_error
end

it "adds the formula to the Brewfile" do
# TODO
end
end

context "the formula is in the Brewfile" do
before do
allow_any_instance_of(Pathname).to receive(:read)
.and_return("brew 'openssl'\nbrew 'wget'")
end

it "raises an error" do
expect { described_class.run("wget") }.to raise_error(RuntimeError)
end
end
end
end