From 6d9a20614aaa1fb2a01e9b1d241b686e760d0023 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 19 May 2020 19:16:17 +0200 Subject: [PATCH] Implement `brew cask help `. --- Library/Homebrew/cask/cmd/help.rb | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/cask/cmd/help.rb b/Library/Homebrew/cask/cmd/help.rb index 51b6ce7876..bfda5ab9a9 100644 --- a/Library/Homebrew/cask/cmd/help.rb +++ b/Library/Homebrew/cask/cmd/help.rb @@ -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