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
38
|
# File 'lib/post_file/cli.rb', line 6
def self.execute(stdout, arguments=[])
options = {
:file_param => 'file'
}
mandatory_options = %w( file address )
parser = OptionParser.new do |opts|
opts.banner = "Usage: post_file -f file_name_to_post -a address_to_post_to [options]"
opts.separator ""
opts.on("-f", "--file=PATH", String, "File to post (e.g. myfile.txt)") { |arg| options[:file] = arg }
opts.on("-a", "--address=ADDRESS", String, "Address to post to (e.g. http://myfileservice.com/recieve)") do |arg|
options[:address] = arg
end
opts.on("-p", "--param=PARAM_NAME", String, "Name of the parameter used for the file in the post request (e.g. file_param), DEFAULT => file") do |arg|
options[:file_param] = arg
end
opts.on("-l", "--local_param=PARAM_NAME", String, "Name of a parameter used to post the exact local path with (e.g. local_file_path)") do |arg|
options[:path_param] = arg
end
opts.on("-n", "--nesting=PARAM_NEST", String, "Parameter name you would like other parameters to be nested in") do |arg|
options[:nesting] = arg
end
opts.on("-h", "--help",
"Show this help message.") { stdout.puts opts; exit }
opts.parse!(arguments)
if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
stdout.puts opts; exit
end
end
post(options)
end
|