class GoRun

Public Class Methods

new(args) click to toggle source
# File lib/go_run.rb, line 7
def initialize(args)
  parse_args(args)
  validate_runfile
  validate_args
  run
end

Public Instance Methods

parse_args(args) click to toggle source
# File lib/go_run.rb, line 14
def parse_args(args)
  @options = OpenStruct.new
  @options.runfile = File.expand_path("./Runfile.yml", `pwd`.strip)
  @opt_parser = OptionParser.new do |opts|
    opts.banner = "Usage: #{$0} [options] target [target ...]"

    opts.on("-r", "--runfile RUNFILE_PATH",
            "Set the location of the Runfile") do |runfile|
      @options.runfile = runfile
    end

    opts.on_tail("-h", "--help", "Show this message") do |runfile|
      puts opts
      exit 0
    end
  end
  @opt_parser.parse!(args)
end
run() click to toggle source
# File lib/go_run.rb, line 55
def run
  runner = Runner.new(Parser.new(@options.runfile).config)
  runner.run(ARGV)
  exit runner.exit_status
end
runfile_exists?() click to toggle source
# File lib/go_run.rb, line 42
def runfile_exists?
  File.file? @options.runfile
end
validate_args() click to toggle source
# File lib/go_run.rb, line 46
def validate_args
  if ARGV.length == 0
    puts "You must choose at least one target"
    puts
    puts @opt_parser.help()
    exit 1
  end
end
validate_runfile() click to toggle source
# File lib/go_run.rb, line 33
def validate_runfile
  if not runfile_exists?
    puts "Runfile not found: #{@options.runfile}"
    puts
    puts @opt_parser.help()
    exit 1
  end
end