optio 0.2.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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +14 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/Optio.html +110 -0
- data/docs/Optio/Exceptions.html +96 -0
- data/docs/Optio/Exceptions/SwitchAlreadyExistsError.html +103 -0
- data/docs/Optio/Parser.html +486 -0
- data/docs/README_md.html +157 -0
- data/docs/created.rid +6 -0
- data/docs/css/fonts.css +167 -0
- data/docs/css/rdoc.css +590 -0
- data/docs/fonts/Lato-Light.ttf +0 -0
- data/docs/fonts/Lato-LightItalic.ttf +0 -0
- data/docs/fonts/Lato-Regular.ttf +0 -0
- data/docs/fonts/Lato-RegularItalic.ttf +0 -0
- data/docs/fonts/SourceCodePro-Bold.ttf +0 -0
- data/docs/fonts/SourceCodePro-Regular.ttf +0 -0
- data/docs/images/add.png +0 -0
- data/docs/images/arrow_up.png +0 -0
- data/docs/images/brick.png +0 -0
- data/docs/images/brick_link.png +0 -0
- data/docs/images/bug.png +0 -0
- data/docs/images/bullet_black.png +0 -0
- data/docs/images/bullet_toggle_minus.png +0 -0
- data/docs/images/bullet_toggle_plus.png +0 -0
- data/docs/images/date.png +0 -0
- data/docs/images/delete.png +0 -0
- data/docs/images/find.png +0 -0
- data/docs/images/loadingAnimation.gif +0 -0
- data/docs/images/macFFBgHack.png +0 -0
- data/docs/images/package.png +0 -0
- data/docs/images/page_green.png +0 -0
- data/docs/images/page_white_text.png +0 -0
- data/docs/images/page_white_width.png +0 -0
- data/docs/images/plugin.png +0 -0
- data/docs/images/ruby.png +0 -0
- data/docs/images/tag_blue.png +0 -0
- data/docs/images/tag_green.png +0 -0
- data/docs/images/transparent.png +0 -0
- data/docs/images/wrench.png +0 -0
- data/docs/images/wrench_orange.png +0 -0
- data/docs/images/zoom.png +0 -0
- data/docs/index.html +159 -0
- data/docs/js/darkfish.js +161 -0
- data/docs/js/jquery.js +4 -0
- data/docs/js/navigation.js +142 -0
- data/docs/js/navigation.js.gz +0 -0
- data/docs/js/search.js +109 -0
- data/docs/js/search_index.js +1 -0
- data/docs/js/search_index.js.gz +0 -0
- data/docs/js/searcher.js +229 -0
- data/docs/js/searcher.js.gz +0 -0
- data/docs/table_of_contents.html +115 -0
- data/exe/optio +10 -0
- data/lib/optio.rb +8 -0
- data/lib/optio/exceptions.rb +6 -0
- data/lib/optio/parser.rb +96 -0
- data/lib/optio/version.rb +3 -0
- data/optio.gemspec +27 -0
- metadata +153 -0
@@ -0,0 +1,103 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>class Optio::Exceptions::SwitchAlreadyExistsError - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<script type="text/javascript">
|
10
|
+
var rdoc_rel_prefix = "../../";
|
11
|
+
var index_rel_prefix = "../../";
|
12
|
+
</script>
|
13
|
+
|
14
|
+
<script src="../../js/jquery.js"></script>
|
15
|
+
<script src="../../js/darkfish.js"></script>
|
16
|
+
|
17
|
+
<link href="../../css/fonts.css" rel="stylesheet">
|
18
|
+
<link href="../../css/rdoc.css" rel="stylesheet">
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
<body id="top" role="document" class="class">
|
23
|
+
<nav role="navigation">
|
24
|
+
<div id="project-navigation">
|
25
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
26
|
+
<h2>
|
27
|
+
<a href="../../index.html" rel="home">Home</a>
|
28
|
+
</h2>
|
29
|
+
|
30
|
+
<div id="table-of-contents-navigation">
|
31
|
+
<a href="../../table_of_contents.html#pages">Pages</a>
|
32
|
+
<a href="../../table_of_contents.html#classes">Classes</a>
|
33
|
+
<a href="../../table_of_contents.html#methods">Methods</a>
|
34
|
+
</div>
|
35
|
+
</div>
|
36
|
+
|
37
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
38
|
+
<form action="#" method="get" accept-charset="utf-8">
|
39
|
+
<div id="search-field-wrapper">
|
40
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
41
|
+
aria-autocomplete="list" aria-controls="search-results"
|
42
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
43
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<ul id="search-results" aria-label="Search Results"
|
47
|
+
aria-busy="false" aria-expanded="false"
|
48
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
49
|
+
</form>
|
50
|
+
</div>
|
51
|
+
|
52
|
+
</div>
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
<div id="class-metadata">
|
57
|
+
|
58
|
+
<div id="parent-class-section" class="nav-section">
|
59
|
+
<h3>Parent</h3>
|
60
|
+
|
61
|
+
|
62
|
+
<p class="link">Object
|
63
|
+
|
64
|
+
</div>
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
</div>
|
70
|
+
</nav>
|
71
|
+
|
72
|
+
<main role="main" aria-labelledby="class-Optio::Exceptions::SwitchAlreadyExistsError">
|
73
|
+
<h1 id="class-Optio::Exceptions::SwitchAlreadyExistsError" class="class">
|
74
|
+
class Optio::Exceptions::SwitchAlreadyExistsError
|
75
|
+
</h1>
|
76
|
+
|
77
|
+
<section class="description">
|
78
|
+
|
79
|
+
</section>
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
</section>
|
95
|
+
</main>
|
96
|
+
|
97
|
+
|
98
|
+
<footer id="validator-badges" role="contentinfo">
|
99
|
+
<p><a href="http://validator.w3.org/check/referer">Validate</a>
|
100
|
+
<p>Generated by <a href="https://rdoc.github.io/rdoc">RDoc</a> 5.0.0.
|
101
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
102
|
+
</footer>
|
103
|
+
|
@@ -0,0 +1,486 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>class Optio::Parser - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<script type="text/javascript">
|
10
|
+
var rdoc_rel_prefix = "../";
|
11
|
+
var index_rel_prefix = "../";
|
12
|
+
</script>
|
13
|
+
|
14
|
+
<script src="../js/jquery.js"></script>
|
15
|
+
<script src="../js/darkfish.js"></script>
|
16
|
+
|
17
|
+
<link href="../css/fonts.css" rel="stylesheet">
|
18
|
+
<link href="../css/rdoc.css" rel="stylesheet">
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
<body id="top" role="document" class="class">
|
23
|
+
<nav role="navigation">
|
24
|
+
<div id="project-navigation">
|
25
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
26
|
+
<h2>
|
27
|
+
<a href="../index.html" rel="home">Home</a>
|
28
|
+
</h2>
|
29
|
+
|
30
|
+
<div id="table-of-contents-navigation">
|
31
|
+
<a href="../table_of_contents.html#pages">Pages</a>
|
32
|
+
<a href="../table_of_contents.html#classes">Classes</a>
|
33
|
+
<a href="../table_of_contents.html#methods">Methods</a>
|
34
|
+
</div>
|
35
|
+
</div>
|
36
|
+
|
37
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
38
|
+
<form action="#" method="get" accept-charset="utf-8">
|
39
|
+
<div id="search-field-wrapper">
|
40
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
41
|
+
aria-autocomplete="list" aria-controls="search-results"
|
42
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
43
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<ul id="search-results" aria-label="Search Results"
|
47
|
+
aria-busy="false" aria-expanded="false"
|
48
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
49
|
+
</form>
|
50
|
+
</div>
|
51
|
+
|
52
|
+
</div>
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
<div id="class-metadata">
|
57
|
+
|
58
|
+
<div id="parent-class-section" class="nav-section">
|
59
|
+
<h3>Parent</h3>
|
60
|
+
|
61
|
+
|
62
|
+
<p class="link">Object
|
63
|
+
|
64
|
+
</div>
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
<!-- Method Quickref -->
|
69
|
+
<div id="method-list-section" class="nav-section">
|
70
|
+
<h3>Methods</h3>
|
71
|
+
|
72
|
+
<ul class="link-list" role="directory">
|
73
|
+
|
74
|
+
<li ><a href="#method-c-new">::new</a>
|
75
|
+
|
76
|
+
<li ><a href="#method-i-banner">#banner</a>
|
77
|
+
|
78
|
+
<li ><a href="#method-i-parse">#parse</a>
|
79
|
+
|
80
|
+
<li ><a href="#method-i-parse-21">#parse!</a>
|
81
|
+
|
82
|
+
<li ><a href="#method-i-rb_parser">#rb_parser</a>
|
83
|
+
|
84
|
+
<li ><a href="#method-i-store_parameter">#store_parameter</a>
|
85
|
+
|
86
|
+
<li ><a href="#method-i-subcommand">#subcommand</a>
|
87
|
+
|
88
|
+
<li ><a href="#method-i-switch">#switch</a>
|
89
|
+
|
90
|
+
</ul>
|
91
|
+
</div>
|
92
|
+
|
93
|
+
</div>
|
94
|
+
</nav>
|
95
|
+
|
96
|
+
<main role="main" aria-labelledby="class-Optio::Parser">
|
97
|
+
<h1 id="class-Optio::Parser" class="class">
|
98
|
+
class Optio::Parser
|
99
|
+
</h1>
|
100
|
+
|
101
|
+
<section class="description">
|
102
|
+
|
103
|
+
<p>A wrapper class for Ruby's <a
|
104
|
+
href="https://ruby-doc.org/stdlib-2.4.1/libdoc/optparse/rdoc/OptionParser.html">OptionParser</a>
|
105
|
+
Usage:</p>
|
106
|
+
|
107
|
+
<pre class="ruby"><span class="ruby-identifier">p</span> = <span class="ruby-constant">Optio</span><span class="ruby-operator">::</span><span class="ruby-constant">Parser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">parser</span><span class="ruby-operator">|</span>
|
108
|
+
<span class="ruby-identifier">parser</span>.<span class="ruby-identifier">switch</span> :<span class="ruby-identifier">verbose</span>, <span class="ruby-identifier">short</span><span class="ruby-operator">:</span> <span class="ruby-string">'v'</span>, <span class="ruby-identifier">desc</span><span class="ruby-operator">:</span> <span class="ruby-string">'Verbose logging'</span>, <span class="ruby-identifier">type</span><span class="ruby-operator">:</span> <span class="ruby-constant">TrueClass</span>
|
109
|
+
<span class="ruby-keyword">end</span>
|
110
|
+
<span class="ruby-identifier">p</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-comment"># or p.parse!(ARGV) or p.parse!(args_array)</span>
|
111
|
+
</pre>
|
112
|
+
|
113
|
+
<p>By default the arguments that are parsed are the ones in <code>ARGV</code></p>
|
114
|
+
|
115
|
+
<h4 id="class-Optio::Parser-label-TODO">TODO<span><a href="#class-Optio::Parser-label-TODO">¶</a> <a href="#top">↑</a></span></h4>
|
116
|
+
|
117
|
+
<p>Implement support for sub commands;</p>
|
118
|
+
|
119
|
+
<pre class="ruby"><span class="ruby-constant">Optio</span><span class="ruby-operator">::</span><span class="ruby-constant">Parser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">parser</span><span class="ruby-operator">|</span>
|
120
|
+
<span class="ruby-identifier">parser</span>.<span class="ruby-identifier">subcommand</span> :<span class="ruby-identifier">dance</span>
|
121
|
+
<span class="ruby-keyword">end</span>
|
122
|
+
</pre>
|
123
|
+
|
124
|
+
</section>
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
|
140
|
+
<header>
|
141
|
+
<h3>Public Class Methods</h3>
|
142
|
+
</header>
|
143
|
+
|
144
|
+
|
145
|
+
<div id="method-c-new" class="method-detail ">
|
146
|
+
|
147
|
+
<div class="method-heading">
|
148
|
+
<span class="method-name">new</span><span
|
149
|
+
class="method-args">() { |self| ... }</span>
|
150
|
+
|
151
|
+
<span class="method-click-advice">click to toggle source</span>
|
152
|
+
|
153
|
+
</div>
|
154
|
+
|
155
|
+
|
156
|
+
<div class="method-description">
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
<div class="method-source-code" id="new-source">
|
164
|
+
<pre><span class="ruby-comment"># File lib/optio/parser.rb, line 21</span>
|
165
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
166
|
+
<span class="ruby-ivar">@switches</span> = {}
|
167
|
+
<span class="ruby-ivar">@subcommands</span> = {}
|
168
|
+
<span class="ruby-ivar">@banner</span> = <span class="ruby-keyword">nil</span>
|
169
|
+
<span class="ruby-ivar">@parsed_params</span> = {}
|
170
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span>
|
171
|
+
<span class="ruby-keyword">yield</span> <span class="ruby-keyword">self</span>
|
172
|
+
<span class="ruby-keyword">end</span>
|
173
|
+
<span class="ruby-keyword">end</span></pre>
|
174
|
+
</div>
|
175
|
+
|
176
|
+
</div>
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
</div>
|
182
|
+
|
183
|
+
|
184
|
+
</section>
|
185
|
+
|
186
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section">
|
187
|
+
<header>
|
188
|
+
<h3>Public Instance Methods</h3>
|
189
|
+
</header>
|
190
|
+
|
191
|
+
|
192
|
+
<div id="method-i-banner" class="method-detail ">
|
193
|
+
|
194
|
+
<div class="method-heading">
|
195
|
+
<span class="method-name">banner</span><span
|
196
|
+
class="method-args">(text)</span>
|
197
|
+
|
198
|
+
<span class="method-click-advice">click to toggle source</span>
|
199
|
+
|
200
|
+
</div>
|
201
|
+
|
202
|
+
|
203
|
+
<div class="method-description">
|
204
|
+
|
205
|
+
<p>Setup the banner for the option parser</p>
|
206
|
+
|
207
|
+
<h4 id="method-i-banner-label-Parameters-3A">Parameters:<span><a href="#method-i-banner-label-Parameters-3A">¶</a> <a href="#top">↑</a></span></h4>
|
208
|
+
<dl class="rdoc-list note-list"><dt>text
|
209
|
+
<dd>
|
210
|
+
<p>Banner text</p>
|
211
|
+
</dd></dl>
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
<div class="method-source-code" id="banner-source">
|
217
|
+
<pre><span class="ruby-comment"># File lib/optio/parser.rb, line 57</span>
|
218
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">banner</span>(<span class="ruby-identifier">text</span>)
|
219
|
+
<span class="ruby-ivar">@banner</span> = <span class="ruby-identifier">text</span>
|
220
|
+
<span class="ruby-keyword">end</span></pre>
|
221
|
+
</div>
|
222
|
+
|
223
|
+
</div>
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
</div>
|
229
|
+
|
230
|
+
|
231
|
+
<div id="method-i-parse" class="method-detail ">
|
232
|
+
|
233
|
+
<div class="method-heading">
|
234
|
+
<span class="method-name">parse</span><span
|
235
|
+
class="method-args">(args = ARGV)</span>
|
236
|
+
|
237
|
+
<span class="method-click-advice">click to toggle source</span>
|
238
|
+
|
239
|
+
</div>
|
240
|
+
|
241
|
+
|
242
|
+
<div class="method-description">
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
<div class="method-source-code" id="parse-source">
|
250
|
+
<pre><span class="ruby-comment"># File lib/optio/parser.rb, line 61</span>
|
251
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">parse</span>(<span class="ruby-identifier">args</span> = <span class="ruby-constant">ARGV</span>)
|
252
|
+
<span class="ruby-identifier">parsed_params</span> = {}
|
253
|
+
<span class="ruby-identifier">rb_parser</span>(<span class="ruby-identifier">parsed_params</span>).<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">args</span>)
|
254
|
+
<span class="ruby-identifier">parsed_params</span>
|
255
|
+
<span class="ruby-keyword">end</span></pre>
|
256
|
+
</div>
|
257
|
+
|
258
|
+
</div>
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
</div>
|
264
|
+
|
265
|
+
|
266
|
+
<div id="method-i-parse-21" class="method-detail ">
|
267
|
+
|
268
|
+
<div class="method-heading">
|
269
|
+
<span class="method-name">parse!</span><span
|
270
|
+
class="method-args">(args = ARGV)</span>
|
271
|
+
|
272
|
+
<span class="method-click-advice">click to toggle source</span>
|
273
|
+
|
274
|
+
</div>
|
275
|
+
|
276
|
+
|
277
|
+
<div class="method-description">
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
|
284
|
+
<div class="method-source-code" id="parse-21-source">
|
285
|
+
<pre><span class="ruby-comment"># File lib/optio/parser.rb, line 67</span>
|
286
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">parse!</span>(<span class="ruby-identifier">args</span> = <span class="ruby-constant">ARGV</span>)
|
287
|
+
<span class="ruby-identifier">parsed_params</span> = {}
|
288
|
+
<span class="ruby-identifier">rb_parser</span>(<span class="ruby-identifier">parsed_params</span>).<span class="ruby-identifier">parse!</span>(<span class="ruby-identifier">args</span>)
|
289
|
+
<span class="ruby-identifier">parsed_params</span>
|
290
|
+
<span class="ruby-keyword">end</span></pre>
|
291
|
+
</div>
|
292
|
+
|
293
|
+
</div>
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
</div>
|
299
|
+
|
300
|
+
|
301
|
+
<div id="method-i-subcommand" class="method-detail ">
|
302
|
+
|
303
|
+
<div class="method-heading">
|
304
|
+
<span class="method-name">subcommand</span><span
|
305
|
+
class="method-args">(subcommand, opts)</span>
|
306
|
+
|
307
|
+
<span class="method-click-advice">click to toggle source</span>
|
308
|
+
|
309
|
+
</div>
|
310
|
+
|
311
|
+
|
312
|
+
<div class="method-description">
|
313
|
+
|
314
|
+
<p>TODO support sub commands</p>
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
<div class="method-source-code" id="subcommand-source">
|
320
|
+
<pre><span class="ruby-comment"># File lib/optio/parser.rb, line 47</span>
|
321
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">subcommand</span>(<span class="ruby-identifier">subcommand</span>, <span class="ruby-identifier">opts</span>)
|
322
|
+
<span class="ruby-identifier">store_parameter</span>(<span class="ruby-identifier">subcommand</span>, <span class="ruby-identifier">opts</span>, <span class="ruby-ivar">@subcommands</span>)
|
323
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>, <span class="ruby-string">'support for sub commands is not yet supported'</span>
|
324
|
+
<span class="ruby-keyword">end</span></pre>
|
325
|
+
</div>
|
326
|
+
|
327
|
+
</div>
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
|
332
|
+
</div>
|
333
|
+
|
334
|
+
|
335
|
+
<div id="method-i-switch" class="method-detail ">
|
336
|
+
|
337
|
+
<div class="method-heading">
|
338
|
+
<span class="method-name">switch</span><span
|
339
|
+
class="method-args">(switch_name, opts = {})</span>
|
340
|
+
|
341
|
+
<span class="method-click-advice">click to toggle source</span>
|
342
|
+
|
343
|
+
</div>
|
344
|
+
|
345
|
+
|
346
|
+
<div class="method-description">
|
347
|
+
|
348
|
+
<p>Define a switch</p>
|
349
|
+
|
350
|
+
<h4 id="method-i-switch-label-Parameters-3A">Parameters:<span><a href="#method-i-switch-label-Parameters-3A">¶</a> <a href="#top">↑</a></span></h4>
|
351
|
+
<dl class="rdoc-list note-list"><dt>switch_name
|
352
|
+
<dd>
|
353
|
+
<p>The name of the switch, i.e. the string that will represent the switch
|
354
|
+
:someswitch will be parsed as <code>--someswitch</code></p>
|
355
|
+
</dd><dt>opts
|
356
|
+
<dd>
|
357
|
+
<p>Additional options for the switch;</p>
|
358
|
+
<ul><li>
|
359
|
+
<p><code>:desc</code> - The description that will be shown for the switch.</p>
|
360
|
+
</li><li>
|
361
|
+
<p><code>:type</code> - Expected argument type, <a
|
362
|
+
href="https://ruby-doc.org/stdlib-2.4.1/libdoc/optparse/rdoc/OptionParser.html#class-OptionParser-label-Type+Coercion">see
|
363
|
+
OptionParser for details</a></p>
|
364
|
+
</li><li>
|
365
|
+
<p><code>:short:</code> - The short switch, i,e <code>-h</code> for
|
366
|
+
<code>--help</code></p>
|
367
|
+
</li></ul>
|
368
|
+
</dd></dl>
|
369
|
+
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
<div class="method-source-code" id="switch-source">
|
374
|
+
<pre><span class="ruby-comment"># File lib/optio/parser.rb, line 42</span>
|
375
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">switch</span>(<span class="ruby-identifier">switch_name</span>, <span class="ruby-identifier">opts</span> = {})
|
376
|
+
<span class="ruby-identifier">store_parameter</span>(<span class="ruby-identifier">switch_name</span>, <span class="ruby-identifier">opts</span>, <span class="ruby-ivar">@switches</span>)
|
377
|
+
<span class="ruby-keyword">end</span></pre>
|
378
|
+
</div>
|
379
|
+
|
380
|
+
</div>
|
381
|
+
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
</div>
|
386
|
+
|
387
|
+
|
388
|
+
</section>
|
389
|
+
|
390
|
+
<section id="private-instance-5Buntitled-5D-method-details" class="method-section">
|
391
|
+
<header>
|
392
|
+
<h3>Private Instance Methods</h3>
|
393
|
+
</header>
|
394
|
+
|
395
|
+
|
396
|
+
<div id="method-i-rb_parser" class="method-detail ">
|
397
|
+
|
398
|
+
<div class="method-heading">
|
399
|
+
<span class="method-name">rb_parser</span><span
|
400
|
+
class="method-args">(parsed_params)</span>
|
401
|
+
|
402
|
+
<span class="method-click-advice">click to toggle source</span>
|
403
|
+
|
404
|
+
</div>
|
405
|
+
|
406
|
+
|
407
|
+
<div class="method-description">
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
|
414
|
+
<div class="method-source-code" id="rb_parser-source">
|
415
|
+
<pre><span class="ruby-comment"># File lib/optio/parser.rb, line 75</span>
|
416
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">rb_parser</span>(<span class="ruby-identifier">parsed_params</span>)
|
417
|
+
<span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">rb_parser</span><span class="ruby-operator">|</span>
|
418
|
+
<span class="ruby-ivar">@switches</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">switch</span>, <span class="ruby-identifier">opts</span><span class="ruby-operator">|</span>
|
419
|
+
<span class="ruby-identifier">rb_parser</span>.<span class="ruby-identifier">on</span>(<span class="ruby-node">"#{switch.to_s.chars.first} IKO"</span>, <span class="ruby-node">"--#{switch} IKO"</span>, <span class="ruby-identifier">opts</span>[<span class="ruby-value">:type</span>], <span class="ruby-identifier">opts</span>[<span class="ruby-value">:desc</span>]) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">param</span><span class="ruby-operator">|</span>
|
420
|
+
<span class="ruby-identifier">parsed_params</span>[<span class="ruby-identifier">switch</span>] = <span class="ruby-identifier">param</span>
|
421
|
+
<span class="ruby-keyword">end</span>
|
422
|
+
<span class="ruby-keyword">end</span>
|
423
|
+
<span class="ruby-keyword">end</span>
|
424
|
+
<span class="ruby-keyword">end</span></pre>
|
425
|
+
</div>
|
426
|
+
|
427
|
+
</div>
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
|
432
|
+
</div>
|
433
|
+
|
434
|
+
|
435
|
+
<div id="method-i-store_parameter" class="method-detail ">
|
436
|
+
|
437
|
+
<div class="method-heading">
|
438
|
+
<span class="method-name">store_parameter</span><span
|
439
|
+
class="method-args">(parameter, opts, mapping)</span>
|
440
|
+
|
441
|
+
<span class="method-click-advice">click to toggle source</span>
|
442
|
+
|
443
|
+
</div>
|
444
|
+
|
445
|
+
|
446
|
+
<div class="method-description">
|
447
|
+
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
<div class="method-source-code" id="store_parameter-source">
|
454
|
+
<pre><span class="ruby-comment"># File lib/optio/parser.rb, line 85</span>
|
455
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">store_parameter</span>(<span class="ruby-identifier">parameter</span>, <span class="ruby-identifier">opts</span>, <span class="ruby-identifier">mapping</span>)
|
456
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">parameter</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">parameter</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
|
457
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"parameter #{parameter} must be of types Atom or String"</span>
|
458
|
+
<span class="ruby-keyword">end</span>
|
459
|
+
<span class="ruby-identifier">parameter_sym</span> = <span class="ruby-identifier">parameter</span>.<span class="ruby-identifier">to_sym</span>
|
460
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">mapping</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">parameter_sym</span>)
|
461
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">Exceptions</span><span class="ruby-operator">::</span><span class="ruby-constant">SwitchAlreadyExistsError</span>, <span class="ruby-node">"parameter #{parameter} already been defined"</span>
|
462
|
+
<span class="ruby-keyword">end</span>
|
463
|
+
<span class="ruby-identifier">mapping</span>[<span class="ruby-identifier">parameter_sym</span>] = <span class="ruby-identifier">opts</span>
|
464
|
+
<span class="ruby-keyword">end</span></pre>
|
465
|
+
</div>
|
466
|
+
|
467
|
+
</div>
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
|
472
|
+
</div>
|
473
|
+
|
474
|
+
|
475
|
+
</section>
|
476
|
+
|
477
|
+
</section>
|
478
|
+
</main>
|
479
|
+
|
480
|
+
|
481
|
+
<footer id="validator-badges" role="contentinfo">
|
482
|
+
<p><a href="http://validator.w3.org/check/referer">Validate</a>
|
483
|
+
<p>Generated by <a href="https://rdoc.github.io/rdoc">RDoc</a> 5.0.0.
|
484
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
485
|
+
</footer>
|
486
|
+
|