Class: GoRun
- Inherits:
-
Object
- Object
- GoRun
- Defined in:
- lib/go_run.rb
Instance Method Summary collapse
-
#initialize(args) ⇒ GoRun
constructor
A new instance of GoRun.
- #parse_args(args) ⇒ Object
- #run ⇒ Object
- #runfile_exists? ⇒ Boolean
- #validate_args ⇒ Object
- #validate_runfile ⇒ Object
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.("./Runfile.yml", `pwd`.strip) @opt_parser = OptionParser.new do |opts| opts. = "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 ⇒ Object
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
42 43 44 |
# File 'lib/go_run.rb', line 42 def runfile_exists? File.file? @options.runfile end |
#validate_args ⇒ Object
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_runfile ⇒ Object
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 |