Class: CC::CLI::Command
- Inherits:
-
Object
show all
- 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
Constructor Details
#initialize(args = []) ⇒ Command
Returns a new instance of Command.
55
56
57
|
# File 'lib/cc/cli/command.rb', line 55
def initialize(args = [])
@args = args
end
|
Class Method Details
.[](name) ⇒ Object
24
25
26
|
# File 'lib/cc/cli/command.rb', line 24
def self.[](name)
all.find { |command| command.name == "#{NAMESPACE}::#{name}" || command.command_name == name }
end
|
.abstract! ⇒ Object
12
13
14
|
# File 'lib/cc/cli/command.rb', line 12
def self.abstract!
@abstract = true
end
|
.abstract? ⇒ Boolean
16
17
18
|
# File 'lib/cc/cli/command.rb', line 16
def self.abstract?
@abstract == true
end
|
.all ⇒ Object
20
21
22
|
# File 'lib/cc/cli/command.rb', line 20
def self.all
@@subclasses.reject(&:abstract?)
end
|
.command_name ⇒ Object
63
64
65
66
67
|
# File 'lib/cc/cli/command.rb', line 63
def self.command_name
name.gsub(/^#{NAMESPACE}::/, "").split("::").map do |part|
part.split(/(?=[A-Z])/).map(&:downcase).join("-")
end.join(":")
end
|
.help ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/cc/cli/command.rb', line 47
def self.help
if const_defined? :HELP
self::HELP
else
short_help
end
end
|
.inherited(subclass) ⇒ Object
rubocop: disable Style/ClassVars
29
30
31
32
|
# File 'lib/cc/cli/command.rb', line 29
def self.inherited(subclass)
@@subclasses ||= []
@@subclasses << subclass
end
|
.short_help ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/cc/cli/command.rb', line 39
def self.short_help
if const_defined? :SHORT_HELP
self::SHORT_HELP
else
""
end
end
|
.synopsis ⇒ Object
rubocop: enable Style/ClassVars
35
36
37
|
# File 'lib/cc/cli/command.rb', line 35
def self.synopsis
"#{command_name} #{self::ARGUMENT_LIST if const_defined?(:ARGUMENT_LIST)}".strip
end
|
Instance Method Details
#execute ⇒ Object
69
70
71
|
# File 'lib/cc/cli/command.rb', line 69
def execute
run
end
|
#fatal(message) ⇒ Object
85
86
87
88
|
# File 'lib/cc/cli/command.rb', line 85
def fatal(message)
$stderr.puts colorize(message, :red)
exit 1
end
|
#require_codeclimate_yml ⇒ Object
90
91
92
93
94
|
# File 'lib/cc/cli/command.rb', line 90
def require_codeclimate_yml
unless filesystem.exist?(CODECLIMATE_YAML)
fatal("No '.codeclimate.yml' file found. Run 'codeclimate init' to generate a config file.")
end
end
|
#run ⇒ Object
59
60
61
|
# File 'lib/cc/cli/command.rb', line 59
def run
$stderr.puts "unknown command #{self.class.name.split("::").last.underscore}"
end
|
#say(message) ⇒ Object
77
78
79
|
# File 'lib/cc/cli/command.rb', line 77
def say(message)
terminal.say message
end
|
#success(message) ⇒ Object
73
74
75
|
# File 'lib/cc/cli/command.rb', line 73
def success(message)
terminal.say colorize(message, :green)
end
|
#warn(message) ⇒ Object
81
82
83
|
# File 'lib/cc/cli/command.rb', line 81
def warn(message)
terminal.say(colorize("WARNING: #{message}", :yellow))
end
|