Class: CC::CLI::Command
- Inherits:
-
Object
show all
- Includes:
- Output
- Defined in:
- lib/cc/cli/command.rb
Constant Summary
collapse
- CODECLIMATE_YAML =
".codeclimate.yml".freeze
- NAMESPACE =
name.split("::")[0..-2].join("::").freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Output
#colorize, #fatal, #rainbow, #say, #success, #terminal, #warn
Constructor Details
#initialize(args = []) ⇒ Command
Returns a new instance of Command.
58
59
60
|
# File 'lib/cc/cli/command.rb', line 58
def initialize(args = [])
@args = args
end
|
Class Method Details
.[](name) ⇒ Object
27
28
29
|
# File 'lib/cc/cli/command.rb', line 27
def self.[](name)
all.find { |command| command.name == "#{NAMESPACE}::#{name}" || command.command_name == name }
end
|
.abstract! ⇒ Object
15
16
17
|
# File 'lib/cc/cli/command.rb', line 15
def self.abstract!
@abstract = true
end
|
.abstract? ⇒ Boolean
19
20
21
|
# File 'lib/cc/cli/command.rb', line 19
def self.abstract?
@abstract == true
end
|
.all ⇒ Object
23
24
25
|
# File 'lib/cc/cli/command.rb', line 23
def self.all
@@subclasses.reject(&:abstract?)
end
|
.command_name ⇒ Object
66
67
68
69
70
|
# File 'lib/cc/cli/command.rb', line 66
def self.command_name
name.gsub(/^#{NAMESPACE}::/, "").split("::").map do |part|
part.split(/(?=[A-Z])/).map(&:downcase).join("-")
end.join(":")
end
|
.help ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/cc/cli/command.rb', line 50
def self.help
if const_defined? :HELP
self::HELP
else
short_help
end
end
|
.inherited(subclass) ⇒ Object
rubocop: disable Style/ClassVars
32
33
34
35
|
# File 'lib/cc/cli/command.rb', line 32
def self.inherited(subclass)
@@subclasses ||= []
@@subclasses << subclass
end
|
.short_help ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/cc/cli/command.rb', line 42
def self.short_help
if const_defined? :SHORT_HELP
self::SHORT_HELP
else
""
end
end
|
.synopsis ⇒ Object
rubocop: enable Style/ClassVars
38
39
40
|
# File 'lib/cc/cli/command.rb', line 38
def self.synopsis
"#{command_name} #{self::ARGUMENT_LIST if const_defined?(:ARGUMENT_LIST)}".strip
end
|
Instance Method Details
#execute ⇒ Object
72
73
74
|
# File 'lib/cc/cli/command.rb', line 72
def execute
run
end
|
#run ⇒ Object
62
63
64
|
# File 'lib/cc/cli/command.rb', line 62
def run
$stderr.puts "unknown command #{self.class.name.split("::").last.underscore}"
end
|