Class: Honey::Okapi::CLI
- Inherits:
-
Object
- Object
- Honey::Okapi::CLI
- Defined in:
- lib/okapi/cli.rb
Instance Method Summary collapse
-
#initialize(args) ⇒ CLI
constructor
A new instance of CLI.
- #parse_config ⇒ Object
- #parse_options!(args) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(args) ⇒ CLI
Returns a new instance of CLI.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/okapi/cli.rb', line 9 def initialize(args) case args.first when 'help' Honey::Okapi::Help.show exit 0 when 'okapi' Honey::Okapi::Help.okapi exit 0 else (args) parse_config @options[:blueprint] ||= BLUEPRINT_PATH @options[:test_spec] ||= TEST_SPEC_PATHS @options[:output] ||= OUTPUT @options[:test_url] ||= TEST_URL @options[:apiary_url] ||= APIARY_URL @options[:test_spec] ||= TEST_SPEC_PATHS.gsub(' ','').split(',') if @options[:params] puts "running with :" p @options puts "\n" end exit run end end |
Instance Method Details
#parse_config ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/okapi/cli.rb', line 50 def parse_config begin if tests = YAML.load_file(@options[:config_path])['tests'] @options[:test_url] ||= tests['host'] if tests['host'] @options[:test_spec] ||= tests['specs'] if tests['specs'] end rescue Errno::ENOENT => e puts "Config file (#{@options[:config_path]}) not accessible ... skiping" puts "\n" rescue Exception => e puts "Config file (#{@options[:config_path]}) loading problem :#{e}" puts "\n" exit 1 end end |
#parse_options!(args) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/okapi/cli.rb', line 66 def (args) @options = {} = OptionParser.new do |opts| opts.on("-c", "--config CONFIG", "path config file (default: " + CONFIG_PATH + " )") do |config| @options[:config_path] = config end opts.on("-b", "--blueprint BLUEPRINT", "path to the blueprint (default: " + BLUEPRINT_PATH + " )") do |blueprint| @options[:blueprint] = blueprint end opts.on("-t","--test_spec TEST_SPEC", "comma separated paths to the test specifications (default: " + TEST_SPEC_PATHS + " )") do |test_spec| @options[:test_spec] = test_spec end opts.on("-o","--output OUTPUT", "output format (default" + OUTPUT + ")") do |output| @options[:output] = output end opts.on("-u","--test_url TEST_URL", "url to test (default" + TEST_URL + ")") do |test_url| @options[:test_url] = test_url end opts.on("-a","--apiary APIARY", "apiary url (default" + APIARY_URL + ")") do |apiary| @options[:apiary_url] = apiary end opts.on("-p","--params [PARAMS]", "show parameters" ) do |params| @options[:params] = true end end .parse! @options[:config_path] ||= CONFIG_PATH @options[:test_spec] = @options[:test_spec].gsub(' ','').split(',') if @options[:test_spec] @options rescue OptionParser::InvalidOption => e puts "\n" puts e Honey::Okapi::Help. puts "\n" exit 1 end |