Merge pull request #7607 from reitermarkus/cask-help-usage

Implement `brew cask help <command>`.
This commit is contained in:
Markus Reiter 2020-05-21 21:02:02 +02:00 committed by GitHub
commit a7a8569d70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 11 deletions

View File

@ -145,7 +145,7 @@ module Cask
command, args = detect_internal_command(*args) || detect_external_command(*args) || [NullCommand.new, args]
if help?
puts command.help
Help.new(command.command_name).run
else
command.run(*args)
end

View File

@ -3,17 +3,26 @@
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
unless command = self.class.commands[command_name]
raise "No help information found for command '#{command_name}'."
end
if command.respond_to?(:usage)
puts command.usage
else
puts command.help
end
else
raise ArgumentError, "#{self.class.command_name} only takes up to one argument."
end
end
def self.purpose
@ -23,6 +32,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