Class: Cask::Cmd::Help

Inherits:
AbstractCommand show all
Defined in:
brew/Library/Homebrew/cask/cmd/help.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractCommand

abstract?, command_name, #initialize, run, visible?

Methods included from Homebrew::Search

#query_regexp, #search_casks, #search_descriptions, #search_formulae, #search_taps

Methods included from Options

#process_arguments

Constructor Details

This class inherits a constructor from Cask::Cmd::AbstractCommand

Class Method Details

.commandsObject



35
36
37
# File 'brew/Library/Homebrew/cask/cmd/help.rb', line 35

def self.commands
  Cmd.command_classes.select(&:visible?).map { |klass| [klass.command_name, klass] }.to_h
end

.helpObject



50
51
52
# File 'brew/Library/Homebrew/cask/cmd/help.rb', line 50

def self.help
  "print help strings for commands"
end

.purposeObject



28
29
30
31
32
33
# File 'brew/Library/Homebrew/cask/cmd/help.rb', line 28

def self.purpose
  <<~EOS
    Homebrew Cask provides a friendly CLI workflow for the administration
    of macOS applications distributed as binaries.
  EOS
end

.usageObject



39
40
41
42
43
44
45
46
47
48
# File 'brew/Library/Homebrew/cask/cmd/help.rb', line 39

def self.usage
  max_command_len = Cmd.commands.map(&:length).max

  "Commands:\n" +
    Cmd.command_classes
       .select(&:visible?)
       .map { |klass| "    #{klass.command_name.ljust(max_command_len)}  #{klass.help}\n" }
       .join +
    %Q(\nSee also "man brew-cask")
end

Instance Method Details

#runObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'brew/Library/Homebrew/cask/cmd/help.rb', line 6

def run
  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