opener-webservice 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,103 +0,0 @@
1
- require 'sinatra/base'
2
- require 'optparse'
3
-
4
- module Opener
5
- class Webservice < Sinatra::Base
6
- class OptParser
7
- attr_accessor :option_parser, :options
8
-
9
- def initialize(&block)
10
- @options = {}
11
- @option_parser = construct_option_parser(options, &block)
12
- end
13
-
14
- def parse(args)
15
- process(:parse, args)
16
- end
17
-
18
- def parse!(args)
19
- process(:parse!, args)
20
- end
21
-
22
- def pre_parse!(args)
23
- delete_double_dash = false
24
- process(:parse!, args, delete_double_dash)
25
- end
26
-
27
- def pre_parse(args)
28
- delete_double_dash = false
29
- process(:parse, args, delete_double_dash)
30
- end
31
-
32
- def self.parse(args)
33
- new.parse(args)
34
- end
35
-
36
- def self.parse!(args)
37
- new.parse!(args)
38
- end
39
-
40
- def self.pre_parse!(args)
41
- new.pre_parse!(args)
42
- end
43
-
44
- def self.pre_parse(args)
45
- new.pre_parse(args)
46
- end
47
-
48
- private
49
-
50
- def process(call, args, delete_double_dash=true)
51
- args.delete("--") if delete_double_dash
52
- option_parser.send(call, args)
53
- return options
54
- end
55
-
56
- def construct_option_parser(options, &block)
57
- script_name = File.basename($0, ".rb")
58
-
59
- OptionParser.new do |opts|
60
- if block_given?
61
- opts.banner = "Usage: #{script_name} <start> [server_options] -- [authentication_options]"
62
- else
63
- opts.banner = "Usage: #{script_name} <start> [options]"
64
- end
65
-
66
- opts.separator ""
67
-
68
- if block_given?
69
- opts.separator "Component Specific options:"
70
- opts.separator ""
71
- yield opts, options
72
- opts.separator ""
73
- end
74
-
75
- opts.separator "Authentication options:"
76
-
77
- opts.on("--authentication", "--authentication AUTHENTICATION_ENDPOINT", "Endpoint for authenticating requests") do |v|
78
- options[:authentication] = v
79
- end
80
-
81
- opts.on("--secret", "--secret SECRET_VARIABLE", "Accepted parameter variable for secret.") do |v|
82
- options[:secret] = v
83
- end
84
-
85
- opts.on("--token", "--secret TOKEN_VARIABLE", "Accepted parameter variable for token.") do |v|
86
- options[:token] = v
87
- end
88
-
89
- opts.separator ""
90
-
91
- opts.separator "Common options:"
92
-
93
- # No argument, shows at tail. This will print an options summary.
94
- # Try it and see!
95
- opts.on_tail("-h", "--help", "Show this message. Usage: #{script_name} -h") do
96
- puts opts
97
- exit
98
- end
99
- end
100
- end
101
- end
102
- end
103
- end