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