Class: Cask::Cmd::AbstractCommand Private

Inherits:
Object
  • Object
show all
Includes:
Homebrew::Search
Defined in:
Library/Homebrew/cask/cmd/abstract_command.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Abstract superclass for all brew cask commands.

Constant Summary collapse

OPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

[
  [:switch, "--[no-]binaries", {
    description: "Disable/enable linking of helper executables. Default: enabled",
    env:         :cask_opts_binaries,
  }],
  [:switch, "--require-sha",  {
    description: "Require all casks to have a checksum.",
    env:         :cask_opts_require_sha,
  }],
  [:switch, "--[no-]quarantine", {
    description: "Disable/enable quarantining of downloads. Default: enabled",
    env:         :cask_opts_quarantine,
  }],
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Homebrew::Search

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

Constructor Details

#initialize(*args) ⇒ AbstractCommand

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of AbstractCommand.


101
102
103
# File 'Library/Homebrew/cask/cmd/abstract_command.rb', line 101

def initialize(*args)
  @args = self.class.parser.parse(args)
end

Instance Attribute Details

#argsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


99
100
101
# File 'Library/Homebrew/cask/cmd/abstract_command.rb', line 99

def args
  @args
end

Class Method Details

.abstract?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

79
80
81
# File 'Library/Homebrew/cask/cmd/abstract_command.rb', line 79

def self.abstract?
  name.split("::").last.match?(/^Abstract[^a-z]/)
end

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


22
23
24
25
26
27
28
29
30
# File 'Library/Homebrew/cask/cmd/abstract_command.rb', line 22

def self.banner_args
  if min_named == :cask && max_named != 1
    " <cask>"
  elsif max_named&.zero?
    ""
  else
    " [<cask>]"
  end
end

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


32
33
34
# File 'Library/Homebrew/cask/cmd/abstract_command.rb', line 32

def self.banner_headline
  "`#{command_name}` [<options>]#{banner_args}"
end

.command_nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


75
76
77
# File 'Library/Homebrew/cask/cmd/abstract_command.rb', line 75

def self.command_name
  @command_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase
end

.helpObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


87
88
89
# File 'Library/Homebrew/cask/cmd/abstract_command.rb', line 87

def self.help
  parser.generate_help_text
end

.max_namedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


18
19
20
# File 'Library/Homebrew/cask/cmd/abstract_command.rb', line 18

def self.max_named
  nil
end

.min_namedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


14
15
16
# File 'Library/Homebrew/cask/cmd/abstract_command.rb', line 14

def self.min_named
  nil
end

.parser(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'Library/Homebrew/cask/cmd/abstract_command.rb', line 51

def self.parser(&block)
  banner = <<~EOS
    `cask` #{banner_headline}

    #{description}
  EOS

  min_n = min_named
  max_n = max_named

  Cmd.parser do
    usage_banner banner

    instance_eval(&block) if block_given?

    OPTIONS.each do |option|
      send(*option)
    end

    min_named min_n unless min_n.nil?
    max_named max_n unless max_n.nil?
  end
end

.run(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


95
96
97
# File 'Library/Homebrew/cask/cmd/abstract_command.rb', line 95

def self.run(*args)
  new(*args).run
end

.short_descriptionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


91
92
93
# File 'Library/Homebrew/cask/cmd/abstract_command.rb', line 91

def self.short_description
  description.split(".").first
end

.visible?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

83
84
85
# File 'Library/Homebrew/cask/cmd/abstract_command.rb', line 83

def self.visible?
  true
end