Class: Hbc::CLI::NullCommand

Inherits:
Object
  • Object
show all
Defined in:
Library/Homebrew/cask/lib/hbc/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(command, *args) ⇒ NullCommand

Returns a new instance of NullCommand



223
224
225
226
# File 'Library/Homebrew/cask/lib/hbc/cli.rb', line 223

def initialize(command, *args)
  @command = command
  @args = args
end

Instance Method Details

#_help_for(klass) ⇒ Object



261
262
263
# File 'Library/Homebrew/cask/lib/hbc/cli.rb', line 261

def _help_for(klass)
  klass.respond_to?(:help) ? klass.help : nil
end

#helpObject



257
258
259
# File 'Library/Homebrew/cask/lib/hbc/cli.rb', line 257

def help
  ""
end

#purposeObject



238
239
240
241
242
243
244
# File 'Library/Homebrew/cask/lib/hbc/cli.rb', line 238

def purpose
  puts <<~EOS
    brew-cask provides a friendly homebrew-style CLI workflow for the
    administration of macOS applications distributed as binaries.

  EOS
end

#run(*_args) ⇒ Object

Raises:

  • (ArgumentError)


228
229
230
231
232
233
234
235
236
# File 'Library/Homebrew/cask/lib/hbc/cli.rb', line 228

def run(*_args)
  purpose
  usage

  return if @command.nil?
  return if @command == "help" && @args.empty?

  raise ArgumentError, "help does not take arguments."
end

#usageObject



246
247
248
249
250
251
252
253
254
255
# File 'Library/Homebrew/cask/lib/hbc/cli.rb', line 246

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

  puts "Commands:\n\n"
  CLI.command_classes.each do |klass|
    next unless klass.visible
    puts "    #{klass.command_name.ljust(max_command_len)}  #{_help_for(klass)}"
  end
  puts %Q(\nSee also "man brew-cask")
end