Class: Oak::Request::Options

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

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



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
122
123
124
125
# File 'lib/oak_api.rb', line 76

def self.parse(args)
  options = {}

  OptionParser.new do |opts|
    opts.program_name = 'oak-api'
    opts.banner = "Usage: #{opts.program_name} [options] [http_verb] [endpoint] [http_body]"

    opts.separator ""
    opts.separator "Options:"

    opts.on("-d", "--debug", "Enable debug mode") do |v|
      options[:debug] = v
    end

    opts.on("-e", "--environment=ENV", "Enable debug mode ") do |v|
      options[:environment] = v
    end

    opts.on("-l", "--list", "List API endpoints") do |v=x|
      options[:list] = v
    end

    opts.on_tail("-a", "--api=VERSION", "Target a specific API version (defaults to latest)") do |v|
      options[:api] = v
    end

    opts.on_tail("-H", "--headers=HEADERS", "HEADERS is a JSON string with HTTP headers") do |v|
      options[:headers] = JSON.parse(v)
    end

    opts.on("-o", "--output=NAME", "Specify output file name") do |v|
      options[:output] = v
    end

    opts.on("-t", "--tree", "Print a welcome message") do |v|
      Oak.greetings
      abort
    end

    opts.on_tail("-h", "--help", "Print help", "something else") do |v|
      abort opts.to_s
    end

    opts.on_tail("-v", "--version", "Print version") do |v|
      abort "#{opts.program_name} #{VERSION}"
    end
  end.parse!(args)

  options
end