-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_me_options.rb
More file actions
37 lines (29 loc) · 925 Bytes
/
parse_me_options.rb
File metadata and controls
37 lines (29 loc) · 925 Bytes
1
2
3
4
5
6
7
8
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
require 'optparse'
require 'ostruct'
@options = OpenStruct.new(key: nil, url: nil)
parser = OptionParser.new do |opts|
opts.banner = 'Usage: ruby infusionsoft.rb -k <YOUR_ENCRYPTED_KEY> -u <YOUR_API_URL>'
opts.summary_indent = ' ' * 8
%w{url key}.each do |name|
short = "-#{ name[0] } <API_#{ name.upcase }>"
long = "--#{ name } <API_#{ name.upcase }>"
description = "API #{ name.upcase } to use"
opts.on(short, long, description){|u| @options[name] = u}
end
opts.on_tail('-h', '--help', 'Show this message') do
puts opts
puts
puts 'For more detailed information, Read the README.rd file'
exit
end
end
parser.parse!
if @options.url.nil? || @options.key.nil?
puts "\e[31m" + '-' * 80
puts 'Need both key and url to execute requrests'
puts '-' * 80 + "\e[0m"
puts parser.help
puts
puts 'For more detailed information, Read the README.rd file'
exit
end