Class: GoRun

Inherits:
Object
  • Object
show all
Defined in:
lib/go_run.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ GoRun

Returns a new instance of GoRun.



7
8
9
10
11
12
# File 'lib/go_run.rb', line 7

def initialize(args)
  parse_args(args)
  validate_runfile
  validate_args
  run
end

Instance Method Details

#parse_args(args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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

#runObject



55
56
57
58
59
# 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?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/go_run.rb', line 42

def runfile_exists?
  File.file? @options.runfile
end

#validate_argsObject



46
47
48
49
50
51
52
53
# 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_runfileObject



33
34
35
36
37
38
39
40
# 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