Skip to content
Permalink
Browse files

Deprecate UnkwnownCommandError (#37)

* Deprecate UnkwnownCommandError and replace it with UnknownCommandError, fixes #35

* Fix rubocop warning

* Add spec for UnkwnownCommandError.new deprecation warning
  • Loading branch information...
d4rky-pl authored and AlfonsoUceda committed May 27, 2018
1 parent 6ee9b20 commit a00614c3f6570fd694240bf78729c048842566a1
@@ -1,12 +1,17 @@
require "hanami/utils/deprecation"

module Hanami
# General purpose Command Line Interface (CLI) framework for Ruby
#
# @since 0.1.0
class CLI
# @since 0.2.0
class Error < StandardError
end

# @since 0.2.0
class UnkwnownCommandError < Error
# @since 0.2.0
# @since 0.2.1
class UnknownCommandError < Error
# @since 0.2.1
# @api private
def initialize(command_name)
super("unknown command: `#{command_name}'")
@@ -28,5 +33,12 @@ def initialize(callback)
super(message)
end
end

# @since 0.2.1
def self.const_missing(name)
super unless name == :UnkwnownCommandError
Hanami::Utils::Deprecation.new('UnkwnownCommandError is deprecated, please use UnknownCommandError')
UnknownCommandError
end
end
end
@@ -87,7 +87,7 @@ def register(name, command = nil, aliases: [], **options)
# it MUST respond to `#call`.
# @param blk [Proc] the callback espressed as a block
#
# @raise [Hanami::CLI::UnkwnownCommandError] if the command isn't registered
# @raise [Hanami::CLI::UnknownCommandError] if the command isn't registered
# @raise [Hanami::CLI::InvalidCallbackError] if the given callback doesn't
# implement the required interface
#
@@ -173,7 +173,7 @@ def before(command_name, callback = nil, &blk)
# it MUST respond to `#call`.
# @param blk [Proc] the callback espressed as a block
#
# @raise [Hanami::CLI::UnkwnownCommandError] if the command isn't registered
# @raise [Hanami::CLI::UnknownCommandError] if the command isn't registered
# @raise [Hanami::CLI::InvalidCallbackError] if the given callback doesn't
# implement the required interface
#
@@ -266,7 +266,7 @@ def get(arguments)
# @api private
def command(command_name)
get(command_name.split(COMMAND_NAME_SEPARATOR)).tap do |result|
raise UnkwnownCommandError.new(command_name) unless result.found?
raise UnknownCommandError.new(command_name) unless result.found?
end
end

@@ -0,0 +1,9 @@
RSpec.describe Hanami::CLI do
describe "UnkwnownCommandError" do
it "shows deprecation message" do
expect do
Hanami::CLI::UnkwnownCommandError.new(:foo)
end.to output(include("UnkwnownCommandError is deprecated, please use UnknownCommandError")).to_stderr
end
end
end
@@ -4,7 +4,7 @@
it "raises error" do
expect do
Bar::CLI::Commands.before("pixel") { puts "hello" }
end.to raise_error(Hanami::CLI::UnkwnownCommandError, "unknown command: `pixel'")
end.to raise_error(Hanami::CLI::UnknownCommandError, "unknown command: `pixel'")
end
end

@@ -34,7 +34,7 @@
it "raises error" do
expect do
Bar::CLI::Commands.after("peta") { puts "hello" }
end.to raise_error(Hanami::CLI::UnkwnownCommandError, "unknown command: `peta'")
end.to raise_error(Hanami::CLI::UnknownCommandError, "unknown command: `peta'")
end
end

0 comments on commit a00614c

Please sign in to comment.
You can’t perform that action at this time.