cli 1.2.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +5 -7
- data/Gemfile.lock +29 -37
- data/README.md +43 -44
- data/Rakefile +1 -28
- data/cli.gemspec +14 -84
- data/examples/httpclient +6 -6
- data/examples/ls +4 -4
- data/examples/processor +5 -5
- data/examples/sinatra +9 -9
- data/lib/cli/dsl.rb +3 -3
- data/rdoc/CLI/Arguments.html +178 -0
- data/rdoc/CLI/DSL/Argument.html +200 -0
- data/rdoc/CLI/DSL/Arguments.html +172 -0
- data/rdoc/CLI/DSL/Base.html +154 -0
- data/rdoc/CLI/DSL/Cast.html +152 -0
- data/rdoc/CLI/DSL/Description.html +150 -0
- data/rdoc/CLI/DSL/Input.html +143 -0
- data/rdoc/CLI/DSL/MultiDefault.html +151 -0
- data/rdoc/CLI/DSL/Option.html +143 -0
- data/rdoc/CLI/DSL/Options.html +142 -0
- data/rdoc/CLI/DSL/Switch.html +267 -0
- data/rdoc/CLI/DSL/Value.html +238 -0
- data/rdoc/CLI/DSL.html +91 -0
- data/rdoc/CLI/Options.html +200 -0
- data/rdoc/CLI/ParserError/ArgumentNameSpecifiedTwice.html +138 -0
- data/rdoc/CLI/ParserError/LongNameSpecifiedTwiceError.html +138 -0
- data/rdoc/CLI/ParserError/MultipleArgumentsSpecifierError.html +138 -0
- data/rdoc/CLI/ParserError/NameArgumetNotSymbolError.html +138 -0
- data/rdoc/CLI/ParserError/OptionsArgumentNotHashError.html +138 -0
- data/rdoc/CLI/ParserError/ShortNameIsInvalidError.html +138 -0
- data/rdoc/CLI/ParserError/ShortNameNotSymbolError.html +138 -0
- data/rdoc/CLI/ParserError/ShortNameSpecifiedTwiceError.html +138 -0
- data/rdoc/CLI/ParserError.html +97 -0
- data/rdoc/CLI/ParsingError/CastError.html +138 -0
- data/rdoc/CLI/ParsingError/MandatoryArgumentNotSpecifiedError.html +138 -0
- data/rdoc/CLI/ParsingError/MandatoryOptionsNotSpecifiedError.html +138 -0
- data/rdoc/CLI/ParsingError/MissingOptionValueError.html +138 -0
- data/rdoc/CLI/ParsingError/UnknownSwitchError.html +138 -0
- data/rdoc/CLI/ParsingError/UsageError.html +97 -0
- data/rdoc/CLI/ParsingError.html +97 -0
- data/rdoc/CLI/Switches.html +306 -0
- data/rdoc/CLI/Values.html +202 -0
- data/rdoc/CLI.html +652 -0
- data/rdoc/README_md.html +553 -0
- data/rdoc/created.rid +7 -0
- data/rdoc/css/fonts.css +167 -0
- data/rdoc/css/rdoc.css +639 -0
- data/rdoc/fonts/Lato-Light.ttf +0 -0
- data/rdoc/fonts/Lato-LightItalic.ttf +0 -0
- data/rdoc/fonts/Lato-Regular.ttf +0 -0
- data/rdoc/fonts/Lato-RegularItalic.ttf +0 -0
- data/rdoc/fonts/SourceCodePro-Bold.ttf +0 -0
- data/rdoc/fonts/SourceCodePro-Regular.ttf +0 -0
- data/rdoc/images/add.png +0 -0
- data/rdoc/images/arrow_up.png +0 -0
- data/rdoc/images/brick.png +0 -0
- data/rdoc/images/brick_link.png +0 -0
- data/rdoc/images/bug.png +0 -0
- data/rdoc/images/bullet_black.png +0 -0
- data/rdoc/images/bullet_toggle_minus.png +0 -0
- data/rdoc/images/bullet_toggle_plus.png +0 -0
- data/rdoc/images/date.png +0 -0
- data/rdoc/images/delete.png +0 -0
- data/rdoc/images/find.png +0 -0
- data/rdoc/images/loadingAnimation.gif +0 -0
- data/rdoc/images/macFFBgHack.png +0 -0
- data/rdoc/images/package.png +0 -0
- data/rdoc/images/page_green.png +0 -0
- data/rdoc/images/page_white_text.png +0 -0
- data/rdoc/images/page_white_width.png +0 -0
- data/rdoc/images/plugin.png +0 -0
- data/rdoc/images/ruby.png +0 -0
- data/rdoc/images/tag_blue.png +0 -0
- data/rdoc/images/tag_green.png +0 -0
- data/rdoc/images/transparent.png +0 -0
- data/rdoc/images/wrench.png +0 -0
- data/rdoc/images/wrench_orange.png +0 -0
- data/rdoc/images/zoom.png +0 -0
- data/rdoc/index.html +120 -0
- data/rdoc/js/darkfish.js +84 -0
- data/rdoc/js/navigation.js +105 -0
- data/rdoc/js/navigation.js.gz +0 -0
- data/rdoc/js/search.js +110 -0
- data/rdoc/js/search_index.js +1 -0
- data/rdoc/js/search_index.js.gz +0 -0
- data/rdoc/js/searcher.js +229 -0
- data/rdoc/js/searcher.js.gz +0 -0
- data/rdoc/table_of_contents.html +533 -0
- data/spec/argument_spec.rb +122 -99
- data/spec/cli_spec.rb +27 -28
- data/spec/conflict_reporting_spec.rb +16 -17
- data/spec/option_spec.rb +79 -56
- data/spec/separator_spec.rb +19 -20
- data/spec/stdin_spec.rb +13 -14
- data/spec/switch_spec.rb +15 -16
- data/spec/usage_spec.rb +80 -81
- metadata +91 -104
- data/.document +0 -5
- data/.rspec +0 -1
- data/VERSION +0 -1
- data/features/cli.feature +0 -9
- data/features/step_definitions/cli_steps.rb +0 -0
- data/features/support/env.rb +0 -13
data/rdoc/CLI.html
ADDED
@@ -0,0 +1,652 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>class CLI - cli 1.3.1</title>
|
8
|
+
|
9
|
+
<script type="text/javascript">
|
10
|
+
var rdoc_rel_prefix = "./";
|
11
|
+
var index_rel_prefix = "./";
|
12
|
+
</script>
|
13
|
+
|
14
|
+
<script src="./js/navigation.js" defer></script>
|
15
|
+
<script src="./js/search.js" defer></script>
|
16
|
+
<script src="./js/search_index.js" defer></script>
|
17
|
+
<script src="./js/searcher.js" defer></script>
|
18
|
+
<script src="./js/darkfish.js" defer></script>
|
19
|
+
|
20
|
+
<link href="./css/fonts.css" rel="stylesheet">
|
21
|
+
<link href="./css/rdoc.css" rel="stylesheet">
|
22
|
+
|
23
|
+
|
24
|
+
<body id="top" role="document" class="class">
|
25
|
+
<nav role="navigation">
|
26
|
+
<div id="project-navigation">
|
27
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
28
|
+
<h2>
|
29
|
+
<a href="./index.html" rel="home">Home</a>
|
30
|
+
</h2>
|
31
|
+
|
32
|
+
<div id="table-of-contents-navigation">
|
33
|
+
<a href="./table_of_contents.html#pages">Pages</a>
|
34
|
+
<a href="./table_of_contents.html#classes">Classes</a>
|
35
|
+
<a href="./table_of_contents.html#methods">Methods</a>
|
36
|
+
</div>
|
37
|
+
</div>
|
38
|
+
|
39
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
40
|
+
<form action="#" method="get" accept-charset="utf-8">
|
41
|
+
<div id="search-field-wrapper">
|
42
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
43
|
+
aria-autocomplete="list" aria-controls="search-results"
|
44
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
45
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
46
|
+
</div>
|
47
|
+
|
48
|
+
<ul id="search-results" aria-label="Search Results"
|
49
|
+
aria-busy="false" aria-expanded="false"
|
50
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
51
|
+
</form>
|
52
|
+
</div>
|
53
|
+
|
54
|
+
</div>
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
<div id="class-metadata">
|
59
|
+
|
60
|
+
|
61
|
+
<div id="parent-class-section" class="nav-section">
|
62
|
+
<h3>Parent</h3>
|
63
|
+
|
64
|
+
<p class="link">Object
|
65
|
+
</div>
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
<!-- Method Quickref -->
|
71
|
+
<div id="method-list-section" class="nav-section">
|
72
|
+
<h3>Methods</h3>
|
73
|
+
|
74
|
+
<ul class="link-list" role="directory">
|
75
|
+
<li ><a href="#method-c-name">::name</a>
|
76
|
+
<li ><a href="#method-c-new">::new</a>
|
77
|
+
<li ><a href="#method-i-argument">#argument</a>
|
78
|
+
<li ><a href="#method-i-arguments">#arguments</a>
|
79
|
+
<li ><a href="#method-i-description">#description</a>
|
80
|
+
<li ><a href="#method-i-option">#option</a>
|
81
|
+
<li ><a href="#method-i-options">#options</a>
|
82
|
+
<li ><a href="#method-i-parse">#parse</a>
|
83
|
+
<li ><a href="#method-i-parse-21">#parse!</a>
|
84
|
+
<li ><a href="#method-i-stdin">#stdin</a>
|
85
|
+
<li ><a href="#method-i-switch">#switch</a>
|
86
|
+
<li ><a href="#method-i-usage">#usage</a>
|
87
|
+
<li ><a href="#method-i-usage-21">#usage!</a>
|
88
|
+
<li ><a href="#method-i-version">#version</a>
|
89
|
+
</ul>
|
90
|
+
</div>
|
91
|
+
|
92
|
+
</div>
|
93
|
+
</nav>
|
94
|
+
|
95
|
+
<main role="main" aria-labelledby="class-CLI">
|
96
|
+
<h1 id="class-CLI" class="class">
|
97
|
+
class CLI
|
98
|
+
</h1>
|
99
|
+
|
100
|
+
<section class="description">
|
101
|
+
|
102
|
+
</section>
|
103
|
+
|
104
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
|
111
|
+
<header>
|
112
|
+
<h3>Public Class Methods</h3>
|
113
|
+
</header>
|
114
|
+
|
115
|
+
<div id="method-c-name" class="method-detail ">
|
116
|
+
<div class="method-heading">
|
117
|
+
<span class="method-name">name</span><span
|
118
|
+
class="method-args">()</span>
|
119
|
+
<span class="method-click-advice">click to toggle source</span>
|
120
|
+
</div>
|
121
|
+
|
122
|
+
<div class="method-description">
|
123
|
+
|
124
|
+
|
125
|
+
<div class="method-source-code" id="name-source">
|
126
|
+
<pre><span class="ruby-comment"># File lib/cli.rb, line 303</span>
|
127
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">name</span>
|
128
|
+
<span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span> <span class="ruby-identifier">$0</span>
|
129
|
+
<span class="ruby-keyword">end</span></pre>
|
130
|
+
</div>
|
131
|
+
</div>
|
132
|
+
|
133
|
+
|
134
|
+
</div>
|
135
|
+
|
136
|
+
<div id="method-c-new" class="method-detail ">
|
137
|
+
<div class="method-heading">
|
138
|
+
<span class="method-name">new</span><span
|
139
|
+
class="method-args">(&block)</span>
|
140
|
+
<span class="method-click-advice">click to toggle source</span>
|
141
|
+
</div>
|
142
|
+
|
143
|
+
<div class="method-description">
|
144
|
+
|
145
|
+
|
146
|
+
<div class="method-source-code" id="new-source">
|
147
|
+
<pre><span class="ruby-comment"># File lib/cli.rb, line 115</span>
|
148
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
149
|
+
<span class="ruby-ivar">@arguments</span> = <span class="ruby-constant">Arguments</span>.<span class="ruby-identifier">new</span>
|
150
|
+
<span class="ruby-ivar">@switches</span> = <span class="ruby-constant">Switches</span>.<span class="ruby-identifier">new</span>
|
151
|
+
<span class="ruby-ivar">@options</span> = <span class="ruby-constant">Options</span>.<span class="ruby-identifier">new</span>
|
152
|
+
|
153
|
+
<span class="ruby-identifier">instance_eval</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span>
|
154
|
+
|
155
|
+
<span class="ruby-identifier">switch</span> <span class="ruby-value">:help</span>, <span class="ruby-value">:short</span> <span class="ruby-operator">=></span> <span class="ruby-value">:h</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=></span> <span class="ruby-string">'display this help message'</span>
|
156
|
+
<span class="ruby-identifier">switch</span> <span class="ruby-value">:version</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=></span> <span class="ruby-string">'display version string'</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@version</span>
|
157
|
+
<span class="ruby-keyword">end</span></pre>
|
158
|
+
</div>
|
159
|
+
</div>
|
160
|
+
|
161
|
+
|
162
|
+
</div>
|
163
|
+
|
164
|
+
</section>
|
165
|
+
|
166
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section">
|
167
|
+
<header>
|
168
|
+
<h3>Public Instance Methods</h3>
|
169
|
+
</header>
|
170
|
+
|
171
|
+
<div id="method-i-argument" class="method-detail ">
|
172
|
+
<div class="method-heading">
|
173
|
+
<span class="method-name">argument</span><span
|
174
|
+
class="method-args">(name, options = {})</span>
|
175
|
+
<span class="method-click-advice">click to toggle source</span>
|
176
|
+
</div>
|
177
|
+
|
178
|
+
<div class="method-description">
|
179
|
+
|
180
|
+
|
181
|
+
<div class="method-source-code" id="argument-source">
|
182
|
+
<pre><span class="ruby-comment"># File lib/cli.rb, line 138</span>
|
183
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">argument</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = {})
|
184
|
+
<span class="ruby-identifier">argument_dsl</span> = <span class="ruby-constant">DSL</span><span class="ruby-operator">::</span><span class="ruby-constant">Argument</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>)
|
185
|
+
|
186
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ParserError</span><span class="ruby-operator">::</span><span class="ruby-constant">ArgumentNameSpecifiedTwice</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">argument_dsl</span>.<span class="ruby-identifier">name</span>) <span class="ruby-keyword">if</span> <span class="ruby-ivar">@arguments</span>.<span class="ruby-identifier">has?</span>(<span class="ruby-identifier">argument_dsl</span>)
|
187
|
+
|
188
|
+
<span class="ruby-ivar">@arguments</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">argument_dsl</span>
|
189
|
+
<span class="ruby-keyword">end</span></pre>
|
190
|
+
</div>
|
191
|
+
</div>
|
192
|
+
|
193
|
+
|
194
|
+
</div>
|
195
|
+
|
196
|
+
<div id="method-i-arguments" class="method-detail ">
|
197
|
+
<div class="method-heading">
|
198
|
+
<span class="method-name">arguments</span><span
|
199
|
+
class="method-args">(name, options = {})</span>
|
200
|
+
<span class="method-click-advice">click to toggle source</span>
|
201
|
+
</div>
|
202
|
+
|
203
|
+
<div class="method-description">
|
204
|
+
|
205
|
+
|
206
|
+
<div class="method-source-code" id="arguments-source">
|
207
|
+
<pre><span class="ruby-comment"># File lib/cli.rb, line 146</span>
|
208
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">arguments</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = {})
|
209
|
+
<span class="ruby-identifier">arguments_dsl</span> = <span class="ruby-constant">DSL</span><span class="ruby-operator">::</span><span class="ruby-constant">Arguments</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>)
|
210
|
+
|
211
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ParserError</span><span class="ruby-operator">::</span><span class="ruby-constant">ArgumentNameSpecifiedTwice</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">arguments_dsl</span>.<span class="ruby-identifier">name</span>) <span class="ruby-keyword">if</span> <span class="ruby-ivar">@arguments</span>.<span class="ruby-identifier">has?</span>(<span class="ruby-identifier">arguments_dsl</span>)
|
212
|
+
|
213
|
+
<span class="ruby-ivar">@arguments</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">arguments_dsl</span>
|
214
|
+
|
215
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ParserError</span><span class="ruby-operator">::</span><span class="ruby-constant">MultipleArgumentsSpecifierError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@arguments</span>.<span class="ruby-identifier">multiary</span>) <span class="ruby-keyword">if</span> <span class="ruby-ivar">@arguments</span>.<span class="ruby-identifier">multiary</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">></span> <span class="ruby-value">1</span>
|
216
|
+
<span class="ruby-keyword">end</span></pre>
|
217
|
+
</div>
|
218
|
+
</div>
|
219
|
+
|
220
|
+
|
221
|
+
</div>
|
222
|
+
|
223
|
+
<div id="method-i-description" class="method-detail ">
|
224
|
+
<div class="method-heading">
|
225
|
+
<span class="method-name">description</span><span
|
226
|
+
class="method-args">(desc)</span>
|
227
|
+
<span class="method-click-advice">click to toggle source</span>
|
228
|
+
</div>
|
229
|
+
|
230
|
+
<div class="method-description">
|
231
|
+
|
232
|
+
|
233
|
+
<div class="method-source-code" id="description-source">
|
234
|
+
<pre><span class="ruby-comment"># File lib/cli.rb, line 126</span>
|
235
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">description</span>(<span class="ruby-identifier">desc</span>)
|
236
|
+
<span class="ruby-ivar">@description</span> = <span class="ruby-identifier">desc</span>
|
237
|
+
<span class="ruby-keyword">end</span></pre>
|
238
|
+
</div>
|
239
|
+
</div>
|
240
|
+
|
241
|
+
|
242
|
+
</div>
|
243
|
+
|
244
|
+
<div id="method-i-option" class="method-detail ">
|
245
|
+
<div class="method-heading">
|
246
|
+
<span class="method-name">option</span><span
|
247
|
+
class="method-args">(name, options = {})</span>
|
248
|
+
<span class="method-click-advice">click to toggle source</span>
|
249
|
+
</div>
|
250
|
+
|
251
|
+
<div class="method-description">
|
252
|
+
|
253
|
+
|
254
|
+
<div class="method-source-code" id="option-source">
|
255
|
+
<pre><span class="ruby-comment"># File lib/cli.rb, line 162</span>
|
256
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">option</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = {})
|
257
|
+
<span class="ruby-identifier">option_dsl</span> = <span class="ruby-constant">DSL</span><span class="ruby-operator">::</span><span class="ruby-constant">Option</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>)
|
258
|
+
<span class="ruby-identifier">check_switch_collision!</span>(<span class="ruby-identifier">option_dsl</span>)
|
259
|
+
<span class="ruby-ivar">@options</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">option_dsl</span>
|
260
|
+
<span class="ruby-keyword">end</span></pre>
|
261
|
+
</div>
|
262
|
+
</div>
|
263
|
+
|
264
|
+
|
265
|
+
</div>
|
266
|
+
|
267
|
+
<div id="method-i-options" class="method-detail ">
|
268
|
+
<div class="method-heading">
|
269
|
+
<span class="method-name">options</span><span
|
270
|
+
class="method-args">(name, options = {})</span>
|
271
|
+
<span class="method-click-advice">click to toggle source</span>
|
272
|
+
</div>
|
273
|
+
|
274
|
+
<div class="method-description">
|
275
|
+
|
276
|
+
|
277
|
+
<div class="method-source-code" id="options-source">
|
278
|
+
<pre><span class="ruby-comment"># File lib/cli.rb, line 168</span>
|
279
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">options</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = {})
|
280
|
+
<span class="ruby-identifier">option_dsl</span> = <span class="ruby-constant">DSL</span><span class="ruby-operator">::</span><span class="ruby-constant">Options</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>)
|
281
|
+
<span class="ruby-identifier">check_switch_collision!</span>(<span class="ruby-identifier">option_dsl</span>)
|
282
|
+
<span class="ruby-ivar">@options</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">option_dsl</span>
|
283
|
+
<span class="ruby-keyword">end</span></pre>
|
284
|
+
</div>
|
285
|
+
</div>
|
286
|
+
|
287
|
+
|
288
|
+
</div>
|
289
|
+
|
290
|
+
<div id="method-i-parse" class="method-detail ">
|
291
|
+
<div class="method-heading">
|
292
|
+
<span class="method-name">parse</span><span
|
293
|
+
class="method-args">(_argv = ARGV, stdin = STDIN, stderr = STDERR)</span>
|
294
|
+
<span class="method-click-advice">click to toggle source</span>
|
295
|
+
</div>
|
296
|
+
|
297
|
+
<div class="method-description">
|
298
|
+
|
299
|
+
|
300
|
+
<div class="method-source-code" id="parse-source">
|
301
|
+
<pre><span class="ruby-comment"># File lib/cli.rb, line 174</span>
|
302
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">parse</span>(<span class="ruby-identifier">_argv</span> = <span class="ruby-constant">ARGV</span>, <span class="ruby-identifier">stdin</span> = <span class="ruby-constant">STDIN</span>, <span class="ruby-identifier">stderr</span> = <span class="ruby-constant">STDERR</span>)
|
303
|
+
<span class="ruby-identifier">values</span> = <span class="ruby-constant">Values</span>.<span class="ruby-identifier">new</span>
|
304
|
+
<span class="ruby-identifier">argv</span> = <span class="ruby-identifier">_argv</span>.<span class="ruby-identifier">dup</span>
|
305
|
+
|
306
|
+
<span class="ruby-comment"># check help and version</span>
|
307
|
+
<span class="ruby-identifier">argv</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">arg</span><span class="ruby-operator">|</span>
|
308
|
+
<span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">arg</span> <span class="ruby-operator">==</span> <span class="ruby-string">'--'</span>
|
309
|
+
|
310
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">arg</span> <span class="ruby-operator">==</span> <span class="ruby-string">'-h'</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">arg</span> <span class="ruby-operator">==</span> <span class="ruby-string">'--help'</span>
|
311
|
+
<span class="ruby-identifier">values</span>.<span class="ruby-identifier">help</span> = <span class="ruby-identifier">usage</span>
|
312
|
+
<span class="ruby-keyword">return</span> <span class="ruby-identifier">values</span>
|
313
|
+
<span class="ruby-keyword">end</span>
|
314
|
+
|
315
|
+
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@version</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">arg</span> <span class="ruby-operator">==</span> <span class="ruby-string">'--version'</span>
|
316
|
+
<span class="ruby-identifier">values</span>.<span class="ruby-identifier">version</span> = <span class="ruby-node">"#{CLI.name} version \"#{@version}\"\n"</span>
|
317
|
+
<span class="ruby-keyword">return</span> <span class="ruby-identifier">values</span>
|
318
|
+
<span class="ruby-keyword">end</span>
|
319
|
+
<span class="ruby-keyword">end</span>
|
320
|
+
|
321
|
+
<span class="ruby-comment"># initialize values</span>
|
322
|
+
<span class="ruby-ivar">@options</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
|
323
|
+
<span class="ruby-identifier">values</span>.<span class="ruby-identifier">value</span>(<span class="ruby-identifier">o</span>, <span class="ruby-keyword">nil</span>)
|
324
|
+
<span class="ruby-keyword">end</span>
|
325
|
+
|
326
|
+
<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">o</span><span class="ruby-operator">|</span>
|
327
|
+
<span class="ruby-identifier">values</span>.<span class="ruby-identifier">value</span>(<span class="ruby-identifier">o</span>, <span class="ruby-keyword">nil</span>)
|
328
|
+
<span class="ruby-keyword">end</span>
|
329
|
+
|
330
|
+
<span class="ruby-comment"># initialize multi options</span>
|
331
|
+
<span class="ruby-ivar">@options</span>.<span class="ruby-identifier">multiary</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
|
332
|
+
<span class="ruby-identifier">values</span>.<span class="ruby-identifier">value</span>(<span class="ruby-identifier">o</span>, [])
|
333
|
+
<span class="ruby-keyword">end</span>
|
334
|
+
|
335
|
+
<span class="ruby-comment"># process switches</span>
|
336
|
+
<span class="ruby-identifier">mandatory_options</span> = <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">mandatory</span>.<span class="ruby-identifier">dup</span>
|
337
|
+
|
338
|
+
<span class="ruby-keyword">while</span> <span class="ruby-keyword">not</span> <span class="ruby-identifier">argv</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">==</span> <span class="ruby-string">'--'</span> <span class="ruby-keyword">and</span> <span class="ruby-constant">Switches</span>.<span class="ruby-identifier">is_switch?</span>(<span class="ruby-identifier">argv</span>.<span class="ruby-identifier">first</span>)
|
339
|
+
<span class="ruby-identifier">arg</span> = <span class="ruby-identifier">argv</span>.<span class="ruby-identifier">shift</span>
|
340
|
+
|
341
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">switch</span> = <span class="ruby-ivar">@switches</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">arg</span>)
|
342
|
+
<span class="ruby-identifier">values</span>.<span class="ruby-identifier">set</span>(<span class="ruby-identifier">switch</span>)
|
343
|
+
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">option</span> = <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">arg</span>)
|
344
|
+
<span class="ruby-identifier">value</span> = <span class="ruby-identifier">argv</span>.<span class="ruby-identifier">shift</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">ParsingError</span><span class="ruby-operator">::</span><span class="ruby-constant">MissingOptionValueError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">option</span>)
|
345
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">option</span>.<span class="ruby-identifier">multiary?</span>
|
346
|
+
<span class="ruby-identifier">values</span>.<span class="ruby-identifier">append</span>(<span class="ruby-identifier">option</span>, <span class="ruby-identifier">option</span>.<span class="ruby-identifier">cast</span>(<span class="ruby-identifier">value</span>))
|
347
|
+
<span class="ruby-keyword">else</span>
|
348
|
+
<span class="ruby-identifier">values</span>.<span class="ruby-identifier">value</span>(<span class="ruby-identifier">option</span>, <span class="ruby-identifier">option</span>.<span class="ruby-identifier">cast</span>(<span class="ruby-identifier">value</span>))
|
349
|
+
<span class="ruby-keyword">end</span>
|
350
|
+
<span class="ruby-identifier">mandatory_options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">option</span>)
|
351
|
+
<span class="ruby-keyword">else</span>
|
352
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ParsingError</span><span class="ruby-operator">::</span><span class="ruby-constant">UnknownSwitchError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">arg</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">switch</span>
|
353
|
+
<span class="ruby-keyword">end</span>
|
354
|
+
<span class="ruby-keyword">end</span>
|
355
|
+
|
356
|
+
<span class="ruby-comment"># set defaults</span>
|
357
|
+
<span class="ruby-ivar">@options</span>.<span class="ruby-identifier">unarry</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
|
358
|
+
<span class="ruby-keyword">next</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">has_default?</span>
|
359
|
+
<span class="ruby-identifier">values</span>.<span class="ruby-identifier">value</span>(<span class="ruby-identifier">o</span>, <span class="ruby-identifier">o</span>.<span class="ruby-identifier">default_cast</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">values</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">o</span>) <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span>
|
360
|
+
<span class="ruby-keyword">end</span>
|
361
|
+
|
362
|
+
<span class="ruby-ivar">@options</span>.<span class="ruby-identifier">multiary</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
|
363
|
+
<span class="ruby-keyword">next</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">has_default?</span>
|
364
|
+
<span class="ruby-identifier">values</span>.<span class="ruby-identifier">value</span>(<span class="ruby-identifier">o</span>, <span class="ruby-identifier">o</span>.<span class="ruby-identifier">default_cast</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">values</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">o</span>) <span class="ruby-operator">==</span> []
|
365
|
+
<span class="ruby-keyword">end</span>
|
366
|
+
|
367
|
+
<span class="ruby-comment"># check mandatory options</span>
|
368
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ParsingError</span><span class="ruby-operator">::</span><span class="ruby-constant">MandatoryOptionsNotSpecifiedError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">mandatory_options</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">mandatory_options</span>.<span class="ruby-identifier">empty?</span>
|
369
|
+
|
370
|
+
<span class="ruby-identifier">argv</span>.<span class="ruby-identifier">shift</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">argv</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">==</span> <span class="ruby-string">'--'</span>
|
371
|
+
|
372
|
+
<span class="ruby-comment"># process arguments</span>
|
373
|
+
<span class="ruby-identifier">arguments</span> = <span class="ruby-ivar">@arguments</span>.<span class="ruby-identifier">dup</span>
|
374
|
+
<span class="ruby-keyword">while</span> <span class="ruby-identifier">argument</span> = <span class="ruby-identifier">arguments</span>.<span class="ruby-identifier">shift</span>
|
375
|
+
<span class="ruby-identifier">value</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">arguments</span>.<span class="ruby-identifier">mandatory</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">argv</span>.<span class="ruby-identifier">length</span>
|
376
|
+
<span class="ruby-identifier">arg</span> = <span class="ruby-identifier">argv</span>.<span class="ruby-identifier">shift</span>
|
377
|
+
|
378
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">argument</span>.<span class="ruby-identifier">multiary?</span>
|
379
|
+
<span class="ruby-identifier">v</span> = [<span class="ruby-identifier">arg</span>]
|
380
|
+
<span class="ruby-keyword">while</span> <span class="ruby-identifier">argv</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">></span> <span class="ruby-identifier">arguments</span>.<span class="ruby-identifier">length</span>
|
381
|
+
<span class="ruby-identifier">v</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">argv</span>.<span class="ruby-identifier">shift</span>
|
382
|
+
<span class="ruby-keyword">end</span>
|
383
|
+
<span class="ruby-identifier">v</span>
|
384
|
+
<span class="ruby-keyword">else</span>
|
385
|
+
<span class="ruby-identifier">arg</span>
|
386
|
+
<span class="ruby-keyword">end</span>
|
387
|
+
<span class="ruby-keyword">else</span>
|
388
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">argument</span>.<span class="ruby-identifier">has_default?</span>
|
389
|
+
<span class="ruby-identifier">argument</span>.<span class="ruby-identifier">default</span>
|
390
|
+
<span class="ruby-keyword">elsif</span> <span class="ruby-keyword">not</span> <span class="ruby-identifier">argument</span>.<span class="ruby-identifier">mandatory?</span>
|
391
|
+
<span class="ruby-identifier">argument</span>.<span class="ruby-identifier">multiary?</span> <span class="ruby-operator">?</span> [] <span class="ruby-operator">:</span> <span class="ruby-keyword">nil</span>
|
392
|
+
<span class="ruby-keyword">else</span>
|
393
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ParsingError</span><span class="ruby-operator">::</span><span class="ruby-constant">MandatoryArgumentNotSpecifiedError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">argument</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">argv</span>.<span class="ruby-identifier">empty?</span>
|
394
|
+
<span class="ruby-keyword">end</span>
|
395
|
+
<span class="ruby-keyword">end</span>
|
396
|
+
|
397
|
+
<span class="ruby-identifier">values</span>.<span class="ruby-identifier">value</span>(<span class="ruby-identifier">argument</span>, <span class="ruby-identifier">argument</span>.<span class="ruby-identifier">cast</span>(<span class="ruby-identifier">value</span>))
|
398
|
+
<span class="ruby-keyword">end</span>
|
399
|
+
|
400
|
+
<span class="ruby-comment"># process stdin</span>
|
401
|
+
<span class="ruby-identifier">values</span>.<span class="ruby-identifier">stdin</span> = <span class="ruby-ivar">@stdin</span>.<span class="ruby-identifier">cast</span>(<span class="ruby-identifier">stdin</span>) <span class="ruby-keyword">if</span> <span class="ruby-ivar">@stdin</span>
|
402
|
+
|
403
|
+
<span class="ruby-identifier">values</span>
|
404
|
+
<span class="ruby-keyword">end</span></pre>
|
405
|
+
</div>
|
406
|
+
</div>
|
407
|
+
|
408
|
+
|
409
|
+
</div>
|
410
|
+
|
411
|
+
<div id="method-i-parse-21" class="method-detail ">
|
412
|
+
<div class="method-heading">
|
413
|
+
<span class="method-name">parse!</span><span
|
414
|
+
class="method-args">(argv = ARGV, stdin = STDIN, stderr = STDERR, stdout = STDOUT) { |pp| ... }</span>
|
415
|
+
<span class="method-click-advice">click to toggle source</span>
|
416
|
+
</div>
|
417
|
+
|
418
|
+
<div class="method-description">
|
419
|
+
|
420
|
+
|
421
|
+
<div class="method-source-code" id="parse-21-source">
|
422
|
+
<pre><span class="ruby-comment"># File lib/cli.rb, line 278</span>
|
423
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">parse!</span>(<span class="ruby-identifier">argv</span> = <span class="ruby-constant">ARGV</span>, <span class="ruby-identifier">stdin</span> = <span class="ruby-constant">STDIN</span>, <span class="ruby-identifier">stderr</span> = <span class="ruby-constant">STDERR</span>, <span class="ruby-identifier">stdout</span> = <span class="ruby-constant">STDOUT</span>)
|
424
|
+
<span class="ruby-keyword">begin</span>
|
425
|
+
<span class="ruby-identifier">pp</span> = <span class="ruby-identifier">parse</span>(<span class="ruby-identifier">argv</span>, <span class="ruby-identifier">stdin</span>, <span class="ruby-identifier">stderr</span>)
|
426
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">pp</span>.<span class="ruby-identifier">help</span>
|
427
|
+
<span class="ruby-identifier">stdout</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">pp</span>.<span class="ruby-identifier">help</span>
|
428
|
+
<span class="ruby-identifier">exit</span> <span class="ruby-value">0</span>
|
429
|
+
<span class="ruby-keyword">end</span>
|
430
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">pp</span>.<span class="ruby-identifier">version</span>
|
431
|
+
<span class="ruby-identifier">stdout</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">pp</span>.<span class="ruby-identifier">version</span>
|
432
|
+
<span class="ruby-identifier">exit</span> <span class="ruby-value">0</span>
|
433
|
+
<span class="ruby-keyword">end</span>
|
434
|
+
|
435
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span>
|
436
|
+
<span class="ruby-keyword">begin</span>
|
437
|
+
<span class="ruby-keyword">yield</span> <span class="ruby-identifier">pp</span>
|
438
|
+
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">RuntimeError</span> <span class="ruby-operator">=></span> <span class="ruby-identifier">e</span>
|
439
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ParsingError</span><span class="ruby-operator">::</span><span class="ruby-constant">UsageError</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
|
440
|
+
<span class="ruby-keyword">end</span>
|
441
|
+
<span class="ruby-keyword">end</span>
|
442
|
+
<span class="ruby-identifier">pp</span>
|
443
|
+
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">ParsingError</span> <span class="ruby-operator">=></span> <span class="ruby-identifier">pe</span>
|
444
|
+
<span class="ruby-identifier">usage!</span>(<span class="ruby-identifier">pe</span>, <span class="ruby-identifier">stderr</span>)
|
445
|
+
<span class="ruby-keyword">end</span>
|
446
|
+
<span class="ruby-keyword">end</span></pre>
|
447
|
+
</div>
|
448
|
+
</div>
|
449
|
+
|
450
|
+
|
451
|
+
</div>
|
452
|
+
|
453
|
+
<div id="method-i-stdin" class="method-detail ">
|
454
|
+
<div class="method-heading">
|
455
|
+
<span class="method-name">stdin</span><span
|
456
|
+
class="method-args">(name = :data, options = {})</span>
|
457
|
+
<span class="method-click-advice">click to toggle source</span>
|
458
|
+
</div>
|
459
|
+
|
460
|
+
<div class="method-description">
|
461
|
+
|
462
|
+
|
463
|
+
<div class="method-source-code" id="stdin-source">
|
464
|
+
<pre><span class="ruby-comment"># File lib/cli.rb, line 134</span>
|
465
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">stdin</span>(<span class="ruby-identifier">name</span> = <span class="ruby-value">:data</span>, <span class="ruby-identifier">options</span> = {})
|
466
|
+
<span class="ruby-ivar">@stdin</span> = <span class="ruby-constant">DSL</span><span class="ruby-operator">::</span><span class="ruby-constant">Input</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>)
|
467
|
+
<span class="ruby-keyword">end</span></pre>
|
468
|
+
</div>
|
469
|
+
</div>
|
470
|
+
|
471
|
+
|
472
|
+
</div>
|
473
|
+
|
474
|
+
<div id="method-i-switch" class="method-detail ">
|
475
|
+
<div class="method-heading">
|
476
|
+
<span class="method-name">switch</span><span
|
477
|
+
class="method-args">(name, options = {})</span>
|
478
|
+
<span class="method-click-advice">click to toggle source</span>
|
479
|
+
</div>
|
480
|
+
|
481
|
+
<div class="method-description">
|
482
|
+
|
483
|
+
|
484
|
+
<div class="method-source-code" id="switch-source">
|
485
|
+
<pre><span class="ruby-comment"># File lib/cli.rb, line 156</span>
|
486
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">switch</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = {})
|
487
|
+
<span class="ruby-identifier">switch_dsl</span> = <span class="ruby-constant">DSL</span><span class="ruby-operator">::</span><span class="ruby-constant">Switch</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>)
|
488
|
+
<span class="ruby-identifier">check_switch_collision!</span>(<span class="ruby-identifier">switch_dsl</span>)
|
489
|
+
<span class="ruby-ivar">@switches</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">switch_dsl</span>
|
490
|
+
<span class="ruby-keyword">end</span></pre>
|
491
|
+
</div>
|
492
|
+
</div>
|
493
|
+
|
494
|
+
|
495
|
+
</div>
|
496
|
+
|
497
|
+
<div id="method-i-usage" class="method-detail ">
|
498
|
+
<div class="method-heading">
|
499
|
+
<span class="method-name">usage</span><span
|
500
|
+
class="method-args">(msg = nil)</span>
|
501
|
+
<span class="method-click-advice">click to toggle source</span>
|
502
|
+
</div>
|
503
|
+
|
504
|
+
<div class="method-description">
|
505
|
+
|
506
|
+
|
507
|
+
<div class="method-source-code" id="usage-source">
|
508
|
+
<pre><span class="ruby-comment"># File lib/cli.rb, line 307</span>
|
509
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">usage</span>(<span class="ruby-identifier">msg</span> = <span class="ruby-keyword">nil</span>)
|
510
|
+
<span class="ruby-identifier">out</span> = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>
|
511
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">msg</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">msg</span>
|
512
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-node">"Usage: #{CLI.name}"</span>
|
513
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-string">' [switches|options]'</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">not</span> <span class="ruby-ivar">@switches</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-keyword">and</span> <span class="ruby-keyword">not</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">optional</span>.<span class="ruby-identifier">empty?</span>
|
514
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-string">' [switches]'</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">not</span> <span class="ruby-ivar">@switches</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-keyword">and</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">optional</span>.<span class="ruby-identifier">empty?</span>
|
515
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-string">' [options]'</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@switches</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-keyword">and</span> <span class="ruby-keyword">not</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">optional</span>.<span class="ruby-identifier">empty?</span>
|
516
|
+
<span class="ruby-ivar">@options</span>.<span class="ruby-identifier">mandatory</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
|
517
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-node">" #{o.switch} <value>"</span>
|
518
|
+
<span class="ruby-keyword">end</span>
|
519
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-string">' [--]'</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">not</span> <span class="ruby-ivar">@arguments</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-keyword">and</span> (<span class="ruby-keyword">not</span> <span class="ruby-ivar">@switches</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-keyword">or</span> <span class="ruby-keyword">not</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">empty?</span>)
|
520
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-string">' '</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@arguments</span>.<span class="ruby-identifier">empty?</span>
|
521
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span>(<span class="ruby-ivar">@arguments</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span>
|
522
|
+
<span class="ruby-identifier">v</span> = <span class="ruby-string">''</span>
|
523
|
+
<span class="ruby-identifier">v</span> <span class="ruby-operator">+=</span> <span class="ruby-string">'['</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">mandatory?</span>
|
524
|
+
<span class="ruby-identifier">v</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">multiary?</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-string">'*'</span><span class="ruby-operator">:</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">to_s</span>
|
525
|
+
<span class="ruby-identifier">v</span> <span class="ruby-operator">+=</span> <span class="ruby-string">']'</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">mandatory?</span>
|
526
|
+
<span class="ruby-identifier">v</span>
|
527
|
+
<span class="ruby-keyword">end</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">' '</span>))
|
528
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-node">" < #{@stdin}"</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@stdin</span>
|
529
|
+
|
530
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span>
|
531
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> <span class="ruby-ivar">@description</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@description</span>
|
532
|
+
|
533
|
+
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@stdin</span> <span class="ruby-keyword">and</span> <span class="ruby-ivar">@stdin</span>.<span class="ruby-identifier">description?</span>
|
534
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">"Input:"</span>
|
535
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">" #{@stdin} - #{@stdin.description}"</span>
|
536
|
+
<span class="ruby-keyword">end</span>
|
537
|
+
|
538
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-ivar">@switches</span>.<span class="ruby-identifier">empty?</span>
|
539
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">"Switches:"</span>
|
540
|
+
<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">s</span><span class="ruby-operator">|</span>
|
541
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-string">' '</span>
|
542
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">switch</span>
|
543
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-node">" (#{s.switch_short})"</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">has_short?</span>
|
544
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-node">" - #{s.description}"</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">description?</span>
|
545
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span>
|
546
|
+
<span class="ruby-keyword">end</span>
|
547
|
+
<span class="ruby-keyword">end</span>
|
548
|
+
|
549
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">empty?</span>
|
550
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">"Options:"</span>
|
551
|
+
<span class="ruby-ivar">@options</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
|
552
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">multiary?</span>
|
553
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-node">" #{o.switch}"</span>
|
554
|
+
<span class="ruby-keyword">else</span>
|
555
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-node">" #{o.switch}*"</span>
|
556
|
+
<span class="ruby-keyword">end</span>
|
557
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-node">" (#{o.switch_short})"</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">has_short?</span>
|
558
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-string">' (mandatory)'</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">mandatory?</span>
|
559
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">has_default_label?</span>
|
560
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-node">" [#{o.default_label}]"</span>
|
561
|
+
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">has_default?</span>
|
562
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-string">" [%s]"</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">default</span>
|
563
|
+
<span class="ruby-keyword">end</span>
|
564
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-node">" - #{o.description}"</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">description?</span>
|
565
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span>
|
566
|
+
<span class="ruby-keyword">end</span>
|
567
|
+
<span class="ruby-keyword">end</span>
|
568
|
+
|
569
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-ivar">@arguments</span>.<span class="ruby-identifier">empty?</span>
|
570
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">"Arguments:"</span>
|
571
|
+
<span class="ruby-ivar">@arguments</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span>
|
572
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">multiary?</span>
|
573
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-node">" #{a}"</span>
|
574
|
+
<span class="ruby-keyword">else</span>
|
575
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-node">" #{a}*"</span>
|
576
|
+
<span class="ruby-keyword">end</span>
|
577
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-string">' (optional)'</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">not</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">mandatory?</span> <span class="ruby-keyword">and</span> <span class="ruby-keyword">not</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">has_default?</span>
|
578
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">has_default_label?</span>
|
579
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-node">" [#{a.default_label}]"</span>
|
580
|
+
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">has_default?</span>
|
581
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-string">" [%s]"</span> <span class="ruby-operator">%</span> (<span class="ruby-identifier">a</span>.<span class="ruby-identifier">default</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">default</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">' '</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">default</span>)
|
582
|
+
<span class="ruby-keyword">end</span>
|
583
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">print</span> <span class="ruby-node">" - #{a.description}"</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">description?</span>
|
584
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span>
|
585
|
+
<span class="ruby-keyword">end</span>
|
586
|
+
<span class="ruby-keyword">end</span>
|
587
|
+
|
588
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">rewind</span>
|
589
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">read</span>
|
590
|
+
<span class="ruby-keyword">end</span></pre>
|
591
|
+
</div>
|
592
|
+
</div>
|
593
|
+
|
594
|
+
|
595
|
+
</div>
|
596
|
+
|
597
|
+
<div id="method-i-usage-21" class="method-detail ">
|
598
|
+
<div class="method-heading">
|
599
|
+
<span class="method-name">usage!</span><span
|
600
|
+
class="method-args">(msg = nil, io = STDERR)</span>
|
601
|
+
<span class="method-click-advice">click to toggle source</span>
|
602
|
+
</div>
|
603
|
+
|
604
|
+
<div class="method-description">
|
605
|
+
|
606
|
+
|
607
|
+
<div class="method-source-code" id="usage-21-source">
|
608
|
+
<pre><span class="ruby-comment"># File lib/cli.rb, line 390</span>
|
609
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">usage!</span>(<span class="ruby-identifier">msg</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">io</span> = <span class="ruby-constant">STDERR</span>)
|
610
|
+
<span class="ruby-identifier">msg</span> = <span class="ruby-node">"Error: #{msg}"</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">msg</span>
|
611
|
+
<span class="ruby-identifier">io</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">usage</span>(<span class="ruby-identifier">msg</span>)
|
612
|
+
<span class="ruby-identifier">exit</span> <span class="ruby-value">42</span>
|
613
|
+
<span class="ruby-keyword">end</span></pre>
|
614
|
+
</div>
|
615
|
+
</div>
|
616
|
+
|
617
|
+
|
618
|
+
</div>
|
619
|
+
|
620
|
+
<div id="method-i-version" class="method-detail ">
|
621
|
+
<div class="method-heading">
|
622
|
+
<span class="method-name">version</span><span
|
623
|
+
class="method-args">(version)</span>
|
624
|
+
<span class="method-click-advice">click to toggle source</span>
|
625
|
+
</div>
|
626
|
+
|
627
|
+
<div class="method-description">
|
628
|
+
|
629
|
+
|
630
|
+
<div class="method-source-code" id="version-source">
|
631
|
+
<pre><span class="ruby-comment"># File lib/cli.rb, line 130</span>
|
632
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">version</span>(<span class="ruby-identifier">version</span>)
|
633
|
+
<span class="ruby-ivar">@version</span> = <span class="ruby-identifier">version</span>.<span class="ruby-identifier">to_s</span>
|
634
|
+
<span class="ruby-keyword">end</span></pre>
|
635
|
+
</div>
|
636
|
+
</div>
|
637
|
+
|
638
|
+
|
639
|
+
</div>
|
640
|
+
|
641
|
+
</section>
|
642
|
+
|
643
|
+
</section>
|
644
|
+
</main>
|
645
|
+
|
646
|
+
|
647
|
+
<footer id="validator-badges" role="contentinfo">
|
648
|
+
<p><a href="https://validator.w3.org/check/referer">Validate</a>
|
649
|
+
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.
|
650
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
651
|
+
</footer>
|
652
|
+
|