diff --git a/lib/boxen/command.rb b/lib/boxen/command.rb index c997f50e..b60b5bf7 100644 --- a/lib/boxen/command.rb +++ b/lib/boxen/command.rb @@ -5,6 +5,8 @@ require "boxen/postflight" class Boxen::Command + class UnknownCommandError < StandardError; end + attr_reader :config def self.help @@ -47,11 +49,12 @@ def self.reset! @commands = {} end - def self.invoke(name, config, *args) - if @commands && @commands.has_key?(name.to_sym) - @commands[name.to_sym].new(config, *args).invoke + def self.invoke(name, *args) + if @commands && name && @commands.has_key?(name.to_sym) + @commands[name.to_sym].new(*args).invoke else - raise "Could not find command #{name}!" + raise UnknownCommandError, + "could not find `#{name}` in the list of registered commands" end end diff --git a/test/boxen_command_test.rb b/test/boxen_command_test.rb index 98a32be2..6efa9ae6 100644 --- a/test/boxen_command_test.rb +++ b/test/boxen_command_test.rb @@ -47,6 +47,18 @@ def @config.debug?; false; end assert_match "foo", stdout end + it "fails with UnknownCommandError if the invoked command is not registered" do + assert_raises Boxen::Command::UnknownCommandError do + Boxen::Command.invoke :random_command + end + end + + it "fails with UnknownCommandError if the invoked command is nil" do + assert_raises Boxen::Command::UnknownCommandError do + Boxen::Command.invoke nil + end + end + it "executes preflight hooks" do Boxen::Command.register :barnette, Boxen::Command::Barnette