Class: AppTester::Parser Abstract
- Inherits:
-
OptionParser
- Object
- OptionParser
- AppTester::Parser
- Defined in:
- lib/app-tester/parser.rb
Overview
This class is abstract.
Parser handler for command line options. This uses optparse ruby gem
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
command line arguments that were set when executing the script.
-
#test_options ⇒ AppTester::Options
readonly
the options that the user defined when he created the framework.
Instance Method Summary collapse
- #check_mandatory_arguments ⇒ Object
-
#initialize(options) ⇒ AppTester::Parser
constructor
Build Parser object.
-
#set_option(symbol, *opts, &block) ⇒ Object
Add a new option to our optparser.
Constructor Details
#initialize(options) ⇒ AppTester::Parser
Build Parser object. Automatically builds with –server argument
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/app-tester/parser.rb', line 18 def initialize @options = { } @test_options = @mandatory_arguments = {} @missing_arguments = [] super do |x| x.separator '' end # Fallback to the first entry on the environments list if there's not default environment selected default_environment = @test_options.default_environment.nil? ? @test_options.environments.keys.first : @test_options.default_environment @options[:server] = @test_options.environments[default_environment] set_option(:server, "-s", "--server OPT", @test_options.environments.keys, "Server to connect. Default: #{default_environment}") ..each do |opt| set_option(opt[:symbol].to_sym, *opt[:opts], &opt[:block]) end end |
Instance Attribute Details
#options ⇒ Hash (readonly)
command line arguments that were set when executing the script
8 9 10 |
# File 'lib/app-tester/parser.rb', line 8 def @options end |
#test_options ⇒ AppTester::Options (readonly)
the options that the user defined when he created the framework
8 9 10 |
# File 'lib/app-tester/parser.rb', line 8 def @test_options end |
Instance Method Details
#check_mandatory_arguments ⇒ Object
62 63 64 65 66 |
# File 'lib/app-tester/parser.rb', line 62 def check_mandatory_arguments @mandatory_arguments.each{|a| a = a[1]; @missing_arguments << "Please supply #{a[:argument]} / #{a[:switch]}" unless @options[a[:key]] } @missing_arguments.each{|a| puts a } exit(1) if @missing_arguments.any? end |
#set_option(symbol, *opts, &block) ⇒ Object
Add a new option to our optparser
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/app-tester/parser.rb', line 46 def set_option(symbol, *opts, &block) @mandatory_arguments[symbol] = {:key => symbol, :argument => opts[0], :switch => opts[1]} if opts[3] == true if block.nil? on(*opts) do |x| case symbol when :server @options[symbol] = @test_options.environments[x] else @options[symbol] = x end end else on(*opts, &block) end end |