aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb
blob: cdb7f5ec830db5f277ca0d3e83b8890aa60ce729 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require_relative "options"

module Hbc
  class CLI
    class AbstractCommand
      include Options

      option "--[no-]binaries", :binaries,      true
      option "--debug",         :debug,         false
      option "--verbose",       :verbose,       false
      option "--outdated",      :outdated_only, false

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

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

      def self.visible
        true
      end

      def self.help
        nil
      end

      def self.needs_init?
        false
      end

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

      attr_accessor :args
      private :args=

      def initialize(*args)
        @args = process_arguments(*args)
      end
    end
  end
end