Class: Apiary::Okapi::CLI

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

Instance Method Summary collapse

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
37
38
39
# File 'lib/okapi/cli.rb', line 9

def initialize(args)
  case args.first
    when 'help'
      Apiary::Okapi::Help.show
      exit 0
    when 'version'
      puts VERSION
      exit 0
    when 'okapi'
      Apiary::Okapi::Help.okapi
      exit 0
    else
      parse_options!(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_configObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/okapi/cli.rb', line 53

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



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
119
120
121
# File 'lib/okapi/cli.rb', line 69

def parse_options!(args)
  @options = {}
  options_parser = 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

  options_parser.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
  Apiary::Okapi::Help.banner
  puts "\n"
  exit 1
end

#runObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/okapi/cli.rb', line 41

def run
  pass = true
  @options[:test_spec].each { |spec|
    pass = Apiary::Okapi::Test.new(@options[:blueprint], spec, @options[:test_url], @options[:output], @options[:apiary_url]).run()
    }
  if pass
    0
  else
    1
  end
end