Implement brew cask help <command>.
This commit is contained in:
parent
b2fc8ad7b3
commit
6d9a20614a
@ -3,17 +3,23 @@
|
||||
module Cask
|
||||
class Cmd
|
||||
class Help < AbstractCommand
|
||||
def initialize(*)
|
||||
super
|
||||
return if args.empty?
|
||||
|
||||
raise ArgumentError, "#{self.class.command_name} does not take arguments."
|
||||
end
|
||||
|
||||
def run
|
||||
puts self.class.purpose
|
||||
puts
|
||||
puts self.class.usage
|
||||
if args.empty?
|
||||
puts self.class.purpose
|
||||
puts
|
||||
puts self.class.usage
|
||||
elsif args.count == 1
|
||||
command_name = args.first
|
||||
|
||||
if (command = self.class.commands[command_name]) && command.respond_to?(:usage)
|
||||
puts command.usage
|
||||
return
|
||||
end
|
||||
|
||||
raise "No help information found for command '#{command_name}'."
|
||||
else
|
||||
raise ArgumentError, "#{self.class.command_name} only takes up to one argument."
|
||||
end
|
||||
end
|
||||
|
||||
def self.purpose
|
||||
@ -23,6 +29,10 @@ module Cask
|
||||
EOS
|
||||
end
|
||||
|
||||
def self.commands
|
||||
Cmd.command_classes.select(&:visible?).map { |klass| [klass.command_name, klass] }.to_h
|
||||
end
|
||||
|
||||
def self.usage
|
||||
max_command_len = Cmd.commands.map(&:length).max
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user