Commit b5dc7c66 authored by Marin Usalj's avatar Marin Usalj

refactored a bit, made it more explicit

parent a725d61a
module Pod module Pod
class Command class Command
class Help < Command class Help < Command
self.summary = 'Show help for the given command' self.summary = 'Show help for the given command.'
self.arguments = '[COMMAND]' self.arguments = '[COMMAND]'
def self.parse(argv) def initialize(argv)
command_needs_help = [argv.shift_argument, '--help'] @help_command = Pod::Command.parse(argv) unless argv.empty?
argv.empty? ? super : Pod::Command.parse(command_needs_help) super
end end
def run def run
help! help_command.help!
end
private
def help_command
@help_command || self
end end
end end
end end
end end
\ No newline at end of file
...@@ -6,17 +6,17 @@ module Pod ...@@ -6,17 +6,17 @@ module Pod
it "invokes the right command with --help flag" do it "invokes the right command with --help flag" do
command = command('help', 'push') command = command('help', 'push')
command.should.be.instance_of Pod::Command::Push command.send(:help_command).should.be.instance_of Pod::Command::Push
lambda { command.validate! }.should.raise CLAide::Help lambda { command.run }.should.raise CLAide::Help
end end
it "raises help! if no other command is passed" do it "raises help! if no other command is passed" do
lambda { command('help').validate! }.should.raise CLAide::Help lambda { command('help').run }.should.raise CLAide::Help
end end
it "shows the right usage" do it "shows the right usage" do
Pod::Command::Help.arguments.should.equal '[COMMAND]' Pod::Command::Help.arguments.should.equal '[COMMAND]'
end end
end end
end end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment