Sha256: 9238bcd74be0bf0585ee2e4f97b9e9dc867d39bf6bdf0413d559e912f5e33f1d

Contents?: true

Size: 1.43 KB

Versions: 4

Compression:

Stored size: 1.43 KB

Contents

require "optparse"

module Datadog
  module CI
    module CLI
      module Command
        class Base
          def exec
            action = build_action
            result = action&.call

            validate!(action)
            output(result)
          end

          private

          def build_action
          end

          def options
            return @options if defined?(@options)

            ddcirb_options = {}
            OptionParser.new do |opts|
              opts.banner = "Usage: bundle exec ddcirb [command] [options]\n Available commands: skippable-tests, skippable-tests-estimate"

              opts.on("-f", "--file FILENAME", "Output result to file FILENAME")
              opts.on("--verbose", "Verbose output to stdout")
              opts.on("--spec-path=[SPEC_PATH]", "Relative path to the spec directory, example: spec")

              command_options(opts)
            end.parse!(into: ddcirb_options)

            @options = ddcirb_options
          end

          def command_options(opts)
          end

          def validate!(action)
            if action.nil? || action.failed
              Datadog.logger.error("ddcirb failed, exiting")
              Kernel.exit(1)
            end
          end

          def output(result)
            if options[:file]
              File.write(options[:file], result)
            else
              print(result)
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
datadog-ci-1.11.0 lib/datadog/ci/cli/command/base.rb
datadog-ci-1.10.0 lib/datadog/ci/cli/command/base.rb
datadog-ci-1.9.0 lib/datadog/ci/cli/command/base.rb
datadog-ci-1.8.1 lib/datadog/ci/cli/command/base.rb