Sha256: 40d1d9ec15cf286fc04c2d0c843ab7f7e1921e3494a8e6368f1289663be9bd5e

Contents?: true

Size: 1.24 KB

Versions: 17

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Buildkite
  module Pipelines
    class Command
      BIN_PATH = 'buildkite-agent'

      def self.pipeline!(*args)
        abort unless pipeline(*args)
      end

      def self.pipeline(subcommand, *args)
        new(:pipeline, subcommand, *args).run
      end

      def self.artifact!(*args)
        abort unless artifact(*args)
      end

      def self.artifact(subcommand, *args)
        new(:artifact, subcommand, *args).run
      end

      def initialize(command, subcommand, *args)
        @command = command.to_s
        @subcommand = subcommand.to_s
        @options = extract_options(args)
        @args = transform_args(args)
      end

      def run
        system(*to_a)
      end

      private

      def to_a
        command = [BIN_PATH, @command, @subcommand]
        command.concat(@options.to_a.flatten)
        command.concat(@args)
      end

      def extract_options(args)
        return {} unless args.first.is_a?(Hash)

        args.shift.tap do |options|
          options.transform_keys! do |key|
            "--#{key.to_s.tr('_', '-')}"
          end
          options.transform_values!(&:to_s)
        end
      end

      def transform_args(args)
        args.map!(&:to_s)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
buildkite-builder-2.0.0 lib/buildkite/pipelines/command.rb
buildkite-builder-2.0.0.beta4 lib/buildkite/pipelines/command.rb
buildkite-builder-2.0.0.beta3 lib/buildkite/pipelines/command.rb
buildkite-builder-2.0.0.beta2 lib/buildkite/pipelines/command.rb
buildkite-builder-2.0.0.beta1 lib/buildkite/pipelines/command.rb
buildkite-builder-1.4.1 lib/buildkite/pipelines/command.rb
buildkite-builder-1.4.0 lib/buildkite/pipelines/command.rb
buildkite-builder-1.3.1 lib/buildkite/pipelines/command.rb
buildkite-builder-1.3.0 lib/buildkite/pipelines/command.rb
buildkite-builder-1.2.0 lib/buildkite/pipelines/command.rb
buildkite-builder-1.1.0 lib/buildkite/pipelines/command.rb
buildkite-builder-1.0.0 lib/buildkite/pipelines/command.rb
buildkite-builder-1.0.0.beta.5 lib/buildkite/pipelines/command.rb
buildkite-builder-1.0.0.beta.4 lib/buildkite/pipelines/command.rb
buildkite-builder-1.0.0.beta.3 lib/buildkite/pipelines/command.rb
buildkite-builder-1.0.0.beta.2 lib/buildkite/pipelines/command.rb
buildkite-builder-1.0.0.beta.1 lib/buildkite/pipelines/command.rb