Class: CLI::Kit::BaseCommand
- Inherits:
-
Object
- Object
- CLI::Kit::BaseCommand
- Defined in:
- lib/cli/kit/base_command.rb
Class Method Summary collapse
- .call(args, command_name) ⇒ Object
- .defined? ⇒ Boolean
- .statsd_increment(_metric, **_kwargs) ⇒ Object
- .statsd_time(_metric, **_kwargs) ⇒ Object
Instance Method Summary collapse
- #call(_args, _command_name) ⇒ Object
- #has_subcommands? ⇒ Boolean
- #stats_tags(args, command_name) ⇒ Object
Class Method Details
.call(args, command_name) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cli/kit/base_command.rb', line 18 def self.call(args, command_name) cmd = new = cmd.(args, command_name) begin statsd_increment('cli.command.invoked', tags: ) statsd_time('cli.command.time', tags: ) do cmd.call(args, command_name) end statsd_increment('cli.command.success', tags: ) rescue Exception => e # rubocop:disable Lint/RescueException statsd_increment('cli.command.exception', tags: + ["exception:#{e.class}"]) raise e end end |
.defined? ⇒ Boolean
6 7 8 |
# File 'lib/cli/kit/base_command.rb', line 6 def self.defined? true end |
.statsd_increment(_metric, **_kwargs) ⇒ Object
10 11 12 |
# File 'lib/cli/kit/base_command.rb', line 10 def self.statsd_increment(_metric, **_kwargs) nil end |
.statsd_time(_metric, **_kwargs) ⇒ Object
14 15 16 |
# File 'lib/cli/kit/base_command.rb', line 14 def self.statsd_time(_metric, **_kwargs) yield end |
Instance Method Details
#call(_args, _command_name) ⇒ Object
40 41 42 |
# File 'lib/cli/kit/base_command.rb', line 40 def call(_args, _command_name) raise NotImplementedError, "#{self.class.name} must implement #{__method__}" end |
#has_subcommands? ⇒ Boolean
44 45 46 |
# File 'lib/cli/kit/base_command.rb', line 44 def has_subcommands? false end |
#stats_tags(args, command_name) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/cli/kit/base_command.rb', line 33 def (args, command_name) = ["task:#{self.class}"] << "command:#{command_name}" if command_name << "subcommand:#{args.first}" if args&.first && has_subcommands? end |