class Buildkite::Pipelines::Command

Constants

BIN_PATH

Public Class Methods

annotate(body, *args) click to toggle source
# File lib/buildkite/pipelines/command.rb, line 24
def self.annotate(body, *args)
  new(:annotate, body, *args).run
end
annotate!(*args) click to toggle source
# File lib/buildkite/pipelines/command.rb, line 28
def self.annotate!(*args)
  abort unless annotate(*args)
end
artifact(subcommand, *args) click to toggle source
# File lib/buildkite/pipelines/command.rb, line 20
def self.artifact(subcommand, *args)
  new(:artifact, subcommand, *args).run
end
artifact!(*args) click to toggle source
# File lib/buildkite/pipelines/command.rb, line 16
def self.artifact!(*args)
  abort unless artifact(*args)
end
new(command, subcommand, *args) click to toggle source
# File lib/buildkite/pipelines/command.rb, line 32
def initialize(command, subcommand, *args)
  @command = command.to_s
  @subcommand = subcommand.to_s
  @options = extract_options(args)
  @args = transform_args(args)
end
pipeline(subcommand, *args) click to toggle source
# File lib/buildkite/pipelines/command.rb, line 12
def self.pipeline(subcommand, *args)
  new(:pipeline, subcommand, *args).run
end
pipeline!(*args) click to toggle source
# File lib/buildkite/pipelines/command.rb, line 8
def self.pipeline!(*args)
  abort unless pipeline(*args)
end

Public Instance Methods

run() click to toggle source
# File lib/buildkite/pipelines/command.rb, line 39
def run
  system(*to_a)
end

Private Instance Methods

extract_options(args) click to toggle source
# File lib/buildkite/pipelines/command.rb, line 51
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
to_a() click to toggle source
# File lib/buildkite/pipelines/command.rb, line 45
def to_a
  command = [BIN_PATH, @command, @subcommand]
  command.concat(@options.to_a.flatten)
  command.concat(@args)
end
transform_args(args) click to toggle source
# File lib/buildkite/pipelines/command.rb, line 62
def transform_args(args)
  args.map!(&:to_s)
end