Class: TestML::Command
- Inherits:
-
Object
- Object
- TestML::Command
- Defined in:
- lib/testml/command.rb
Constant Summary collapse
- VERSION =
'0.0.1'
Instance Method Summary collapse
- #error(msg) ⇒ Object
- #get_options(args) ⇒ Object
-
#initialize(args) ⇒ Command
constructor
A new instance of Command.
- #run ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize(args) ⇒ Command
Returns a new instance of Command.
19 20 21 22 23 24 25 26 |
# File 'lib/testml/command.rb', line 19 def initialize(args) @args = args @file = nil @testml = nil @bridge = [] @argv = [] (args) end |
Instance Method Details
#error(msg) ⇒ Object
66 67 68 |
# File 'lib/testml/command.rb', line 66 def error(msg) fail "Error: #{msg}\n\n#{usage}\n" end |
#get_options(args) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/testml/command.rb', line 28 def (args) while arg = args.shift if arg =~ /^(?:-b|--bridge(?:=(.*))?)$/ b = $1 || args.shift or error '-b|--bridge requires a value' @bridge.concat(b.split(',')) elsif File.exists?(arg) @file = arg break elsif arg =~ /^--?$/ break elsif arg !~ /^-/ error "Input file '#{arg}' does not exist" else error "Unrecognized argument '#{arg}'" end end @testml = @file ? File.read(@file) : STDIN.read @argv = TestML::List.new(args.map {|a| TestML::String.new(a)}) end |
#run ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/testml/command.rb', line 49 def run @runtime = TestML::Runtime::Lang.new( testml: @testml, bridge: @bridge, compiler: TestML::Compiler::Pegex, library: [ TestML::Library::Standard, TestML::Library::Debug, ], ) @runtime.compile_testml @runtime.initialize_runtime #XXX @runtime @runtime.global.setvar('ARGV', @argv) @runtime.run_function(@runtime.function, []) end |
#usage ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/testml/command.rb', line 9 def usage "Usage:\ntestml [testml-options] (<testml-file> | -) [runtime arguments]\n\nTestML Options:\n-b, --bridge= <bridge-class[,bridge-class-list]>\n" end |