Sha256: 0842d3d70251a4a03096902b61bd671b7b1f6fcaa822f5e7c060684a208294bb

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

require 'cli/kit'

module CLI
  module Kit
    class BaseCommand
      def self.defined?
        true
      end

      def self.statsd_increment(_metric, **_kwargs)
        nil
      end

      def self.statsd_time(_metric, **_kwargs)
        yield
      end

      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

      def call(_args, _command_name)
        raise NotImplementedError
      end

      def has_subcommands?
        false
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cli-kit-3.0.1 lib/cli/kit/base_command.rb
cli-kit-3.0.0 lib/cli/kit/base_command.rb