class Buildkite::Builder::Commands::Abstract
Constants
- PIPELINES_DIRECTORY
- POSSIBLE_PIPELINES_PATHS
- POSSIBLE_PIPELINE_PATHS
Attributes
description[RW]
options[R]
Public Class Methods
execute()
click to toggle source
# File lib/buildkite/builder/commands/abstract.rb, line 24 def execute new.execute end
new()
click to toggle source
# File lib/buildkite/builder/commands/abstract.rb, line 31 def initialize @options = {} parser = OptionParser.new do |opts| opts.banner = "Usage: buildkite-builder #{command_name} [OPTIONS] [PIPELINE]" opts.on('-h', '--help', 'Prints this help') do options[:help] = opts end parse_options(opts) end parser.parse! end
Public Instance Methods
execute()
click to toggle source
# File lib/buildkite/builder/commands/abstract.rb, line 46 def execute if options[:help] puts options[:help] return elsif !pipeline_path abort "Unable to find pipeline" end run end
Private Instance Methods
command_name()
click to toggle source
# File lib/buildkite/builder/commands/abstract.rb, line 63 def command_name Commands::COMMANDS.key(self.class.name.split('::').last.to_sym) end
find_root_by_main_pipeline()
click to toggle source
# File lib/buildkite/builder/commands/abstract.rb, line 88 def find_root_by_main_pipeline POSSIBLE_PIPELINE_PATHS.map { |path| Builder.root.join(path) }.find(&:exist?)&.dirname end
find_root_by_multi_pipeline()
click to toggle source
# File lib/buildkite/builder/commands/abstract.rb, line 92 def find_root_by_multi_pipeline pipelines_path = POSSIBLE_PIPELINES_PATHS.map { |path| Builder.root.join(path) }.find(&:directory?) if pipelines_path if pipeline_slug path = pipelines_path.join(pipeline_slug) path if path.directory? elsif pipelines_path.children.one? pipelines_path.children.first else raise 'Your project has multiple pipelines, please specify one.' end end end
log()
click to toggle source
# File lib/buildkite/builder/commands/abstract.rb, line 72 def log @log ||= begin Logger.new($stdout).tap do |logger| logger.formatter = proc do |_severity, _datetime, _progname, msg| "#{msg}\n" end end end end
parse_options(opts)
click to toggle source
# File lib/buildkite/builder/commands/abstract.rb, line 67 def parse_options(opts) # noop # Subclasses should override to parse options. end
pipeline_path()
click to toggle source
# File lib/buildkite/builder/commands/abstract.rb, line 82 def pipeline_path @pipeline_path ||= find_root_by_main_pipeline || find_root_by_multi_pipeline end
pipeline_slug()
click to toggle source
# File lib/buildkite/builder/commands/abstract.rb, line 59 def pipeline_slug ARGV.last || Buildkite.env&.pipeline_slug end