Class: CLI::Kit::BaseCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/kit/base_command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(args, command_name) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cli/kit/base_command.rb', line 18

def self.call(args, command_name)
  cmd = new
  stats_tags = ["task:#{cmd.class}"]
  stats_tags << "subcommand:#{args.first}" if args && args.first && cmd.has_subcommands?
  begin
    statsd_increment("cli.command.invoked", tags: stats_tags)
    statsd_time("cli.command.time", tags: stats_tags) do
      cmd.call(args, command_name)
    end
    statsd_increment("cli.command.success", tags: stats_tags)
  rescue => e
    statsd_increment("cli.command.exception", tags: stats_tags + ["exception:#{e.class}"])
    raise e
  end
end

.defined?Boolean

Returns:

  • (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

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/cli/kit/base_command.rb', line 34

def call(_args, _command_name)
  raise NotImplementedError
end

#has_subcommands?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/cli/kit/base_command.rb', line 38

def has_subcommands?
  false
end