Class: Cucumber::Formatter::CurlOptionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/http_io.rb

Class Method Summary collapse

Class Method Details

.parse(options) ⇒ Object

Raises:

  • (StandardError)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/http_io.rb', line 21

def self.parse(options)
  args = Shellwords.split(options)

  url = nil
  http_method = 'PUT'
  headers = {}

  until args.empty?
    arg = args.shift
    case arg
    when '-X', '--request'
      http_method = remove_arg_for(args, arg)
    when '-H'
      header_arg = remove_arg_for(args, arg)
      headers = headers.merge(parse_header(header_arg))
    else
      raise StandardError, "#{options} was not a valid curl command. Can't set url to #{arg} it is already set to #{url}" if url

      url = arg
    end
  end
  raise StandardError, "#{options} was not a valid curl command" unless url

  [
    url,
    http_method,
    headers
  ]
end

.parse_header(header_arg) ⇒ Object

Raises:

  • (StandardError)


57
58
59
60
61
62
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/http_io.rb', line 57

def self.parse_header(header_arg)
  parts = header_arg.split(':', 2)
  raise StandardError, "#{header_arg} was not a valid header" unless parts.length == 2

  { parts[0].strip => parts[1].strip }
end

.remove_arg_for(args, arg) ⇒ Object

Raises:

  • (StandardError)


51
52
53
54
55
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/http_io.rb', line 51

def self.remove_arg_for(args, arg)
  return args.shift unless args.empty?

  raise StandardError, "Missing argument for #{arg}"
end