como 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +4 -0
- data/doc/Como/ArgsParseState.html +53 -53
- data/doc/Como/ComoCommon.html +4 -4
- data/doc/Como/MainOpt.html +51 -51
- data/doc/Como/Opt/ErrorWithData.html +4 -4
- data/doc/Como/Opt/InvalidOption.html +4 -4
- data/doc/Como/Opt/MissingArgument.html +4 -4
- data/doc/Como/Opt.html +913 -511
- data/doc/Como/RuleCheck.html +89 -89
- data/doc/Como/RuleDisplay.html +84 -84
- data/doc/Como/Spec.html +16 -16
- data/doc/Como.html +129 -123
- data/doc/_index.html +5 -5
- data/doc/class_list.html +6 -1
- data/doc/css/style.css +2 -1
- data/doc/file.CHANGELOG.html +27 -23
- data/doc/file.README.html +10 -10
- data/doc/file_list.html +6 -1
- data/doc/frames.html +5 -7
- data/doc/index.html +10 -10
- data/doc/js/app.js +7 -2
- data/doc/js/full_list.js +9 -6
- data/doc/method_list.html +167 -132
- data/doc/top-level-namespace.html +4 -4
- data/lib/como.rb +41 -11
- data/lib/version.rb +1 -1
- metadata +2 -2
data/doc/Como.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Module: Como
|
8
8
|
|
9
|
-
— Documentation by YARD 0.8.6
|
9
|
+
— Documentation by YARD 0.8.7.6
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -17,7 +17,7 @@
|
|
17
17
|
<script type="text/javascript" charset="utf-8">
|
18
18
|
hasFrames = window.top.frames.main ? true : false;
|
19
19
|
relpath = '';
|
20
|
-
framesUrl = "frames.html#!"
|
20
|
+
framesUrl = "frames.html#!Como.html";
|
21
21
|
</script>
|
22
22
|
|
23
23
|
|
@@ -91,7 +91,7 @@
|
|
91
91
|
|
92
92
|
<p>Como</p>
|
93
93
|
|
94
|
-
<h1>Introduction</h1>
|
94
|
+
<h1 id="label-Introduction">Introduction</h1>
|
95
95
|
|
96
96
|
<p>Como provides low manifest command line option parsing and deployment. The
|
97
97
|
command line options are described in compact table format and option
|
@@ -100,18 +100,18 @@ usage information based on the option table (+ generic program info) and
|
|
100
100
|
displays it automatically if necessary. Como supports also subcommands and
|
101
101
|
checking for option combinations using a simple DSL.</p>
|
102
102
|
|
103
|
-
<h1>Usage Examples</h1>
|
103
|
+
<h1 id="label-Usage+Examples">Usage Examples</h1>
|
104
104
|
|
105
105
|
<p>Two simple examples are presented in this section. First one includes a
|
106
106
|
straight forward command definition and the second is a bit more
|
107
107
|
complicated with subcommand feature in use.</p>
|
108
108
|
|
109
|
-
<h2>Simple example</h2>
|
109
|
+
<h2 id="label-Simple+example">Simple example</h2>
|
110
110
|
|
111
|
-
<p>Below is a small example program (
|
111
|
+
<p>Below is a small example program (“como_simple”) that demonstrates typical
|
112
112
|
usage.</p>
|
113
113
|
|
114
|
-
<h3>Program listing</h3>
|
114
|
+
<h3 id="label-Program+listing">Program listing</h3>
|
115
115
|
|
116
116
|
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>como</span><span class='tstring_end'>"</span></span>
|
117
117
|
<span class='id identifier rubyid_include'>include</span> <span class='const'>Como</span>
|
@@ -123,22 +123,23 @@ usage.</p>
|
|
123
123
|
<span class='lbracket'>[</span> <span class='symbol'>:switch</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>debug</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>-d</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Enable debugging.</span><span class='tstring_end'>"</span></span> <span class='rbracket'>]</span><span class='comma'>,</span>
|
124
124
|
<span class='rbracket'>]</span> <span class='rparen'>)</span>
|
125
125
|
|
126
|
-
<span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> File option: </span><span class='embexpr_beg'>#{</span><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'
|
127
|
-
<span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> Debugging selected!</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'
|
126
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> File option: </span><span class='embexpr_beg'>#{</span><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>file</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
127
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> Debugging selected!</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>debug</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_given'>given</span>
|
128
|
+
</code></pre>
|
128
129
|
|
129
130
|
<p>First Como is required and Como module is included.</p>
|
130
131
|
|
131
132
|
<p><span class='object_link'><a href="Como/Spec.html#command-class_method" title="Como::Spec.command (method)">Spec.command</a></span> method takes 4 arguments:</p>
|
132
|
-
<dl class="rdoc-list"><dt>progname
|
133
|
+
<dl class="rdoc-list label-list"><dt>progname
|
133
134
|
<dd>
|
134
135
|
<p>Name of the program (or command).</p>
|
135
|
-
</dd><dt>author
|
136
|
+
</dd><dt>author
|
136
137
|
<dd>
|
137
138
|
<p>Author of the program.</p>
|
138
|
-
</dd><dt>year
|
139
|
+
</dd><dt>year
|
139
140
|
<dd>
|
140
141
|
<p>Year (or any date) for the program.</p>
|
141
|
-
</dd><dt>option table
|
142
|
+
</dd><dt>option table
|
142
143
|
<dd>
|
143
144
|
<p>Description of the command options.</p>
|
144
145
|
</dd></dl>
|
@@ -149,10 +150,10 @@ option:</p>
|
|
149
150
|
<pre class="code ruby"><code class="ruby"><span class='lbracket'>[</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_mnemonic'>mnemonic</span><span class='comma'>,</span> <span class='id identifier rubyid_doc'>doc</span> <span class='rbracket'>]</span></code></pre>
|
150
151
|
|
151
152
|
<p>Two different types are present in the example:</p>
|
152
|
-
<dl class="rdoc-list"><dt>:single
|
153
|
+
<dl class="rdoc-list label-list"><dt>:single
|
153
154
|
<dd>
|
154
155
|
<p>Single means that the option requires one argument (and only one).</p>
|
155
|
-
</dd><dt>:switch
|
156
|
+
</dd><dt>:switch
|
156
157
|
<dd>
|
157
158
|
<p>Switch is an optional flag (default value is false).</p>
|
158
159
|
</dd></dl>
|
@@ -161,26 +162,26 @@ option:</p>
|
|
161
162
|
command line option values are stored automatically. For example the file
|
162
163
|
option value is returned by:</p>
|
163
164
|
|
164
|
-
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'
|
165
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>file</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span></code></pre>
|
165
166
|
|
166
167
|
<p>The option name also doubles as long option format, i.e. one could use
|
167
|
-
|
168
|
+
“–file <filename>” on the command line.</p>
|
168
169
|
|
169
170
|
<p>Existence of optional options can be tested using the <span class='object_link'><a href="Como/Opt.html#given-instance_method" title="Como::Opt#given (method)">Opt#given</a></span> method.
|
170
171
|
For example</p>
|
171
172
|
|
172
|
-
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'
|
173
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>debug</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_given'>given</span></code></pre>
|
173
174
|
|
174
|
-
<p>would return
|
175
|
+
<p>would return “true” if “-d” was given on the command line.</p>
|
175
176
|
|
176
|
-
<p>Mnemonic is the short form option specification e.g.
|
177
|
-
replaced with
|
177
|
+
<p>Mnemonic is the short form option specification e.g. “-f”. If short form is
|
178
|
+
replaced with “nil”, the long option format is only available.</p>
|
178
179
|
|
179
|
-
<p>Doc includes documentation for the option. It is displayed when
|
180
|
-
(
|
180
|
+
<p>Doc includes documentation for the option. It is displayed when “help”
|
181
|
+
(“-h”) option is given. Help option is added to the command automatically
|
181
182
|
as default behavior.</p>
|
182
183
|
|
183
|
-
<h3>Simple example executions</h3>
|
184
|
+
<h3 id="label-Simple+example+executions">Simple example executions</h3>
|
184
185
|
|
185
186
|
<p>Normal behavior would be achieved by executing:</p>
|
186
187
|
|
@@ -197,7 +198,7 @@ as default behavior.</p>
|
|
197
198
|
|
198
199
|
<p>Since option name doubles as long option.</p>
|
199
200
|
|
200
|
-
<p>Como includes certain
|
201
|
+
<p>Como includes certain “extra” behavior out-of-box. Required arguments are
|
201
202
|
checked for existence and error is displayed if arguments are not given.</p>
|
202
203
|
|
203
204
|
<p>For example given the command:</p>
|
@@ -215,22 +216,22 @@ checked for existence and error is displayed if arguments are not given.</p>
|
|
215
216
|
|
216
217
|
Copyright (c) 2013 by Programmer</code></pre>
|
217
218
|
|
218
|
-
<p>Missing option error is displayed since
|
219
|
-
error message is followed by
|
220
|
-
string is taken from the option specification to
|
219
|
+
<p>Missing option error is displayed since “file” is a mandatory option. The
|
220
|
+
error message is followed by “usage” display (Usage Help). Documentation
|
221
|
+
string is taken from the option specification to “usage” display.</p>
|
221
222
|
|
222
223
|
<p>Given the command:</p>
|
223
224
|
|
224
225
|
<pre class="code ruby"><code class="ruby">shell> como_simple -h</code></pre>
|
225
226
|
|
226
|
-
<p>would display the same
|
227
|
+
<p>would display the same “usage” screen except without the error line.</p>
|
227
228
|
|
228
|
-
<h2>Subcommand example</h2>
|
229
|
+
<h2 id="label-Subcommand+example">Subcommand example</h2>
|
229
230
|
|
230
231
|
<p>Subcmd example includes a program which has subcommands. Subcommands can
|
231
232
|
have their own command line switches and options.</p>
|
232
233
|
|
233
|
-
<h3>Program listing</h3>
|
234
|
+
<h3 id="label-Program+listing">Program listing</h3>
|
234
235
|
|
235
236
|
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>como</span><span class='tstring_end'>"</span></span>
|
236
237
|
<span class='id identifier rubyid_include'>include</span> <span class='const'>Como</span>
|
@@ -251,8 +252,8 @@ have their own command line switches and options.</p>
|
|
251
252
|
|
252
253
|
<span class='id identifier rubyid_check'>check</span> <span class='kw'>do</span>
|
253
254
|
<span class='id identifier rubyid_one'>one</span><span class='lparen'>(</span>
|
254
|
-
<span class='tstring'><span class='tstring_beg'
|
255
|
-
<span class='id identifier rubyid_all'>all</span><span class='lparen'>(</span> <span class='tstring'><span class='tstring_beg'
|
255
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>-fo</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
256
|
+
<span class='id identifier rubyid_all'>all</span><span class='lparen'>(</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>password</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>username</span><span class='tstring_end'>'</span></span> <span class='rparen'>)</span>
|
256
257
|
<span class='rparen'>)</span>
|
257
258
|
<span class='kw'>end</span>
|
258
259
|
|
@@ -265,26 +266,27 @@ have their own command line switches and options.</p>
|
|
265
266
|
<span class='id identifier rubyid_subcmd'>subcmd</span> <span class='op'>=</span> <span class='const'>Opt</span><span class='period'>.</span><span class='id identifier rubyid_main'>main</span><span class='period'>.</span><span class='id identifier rubyid_givenSubcmd'>givenSubcmd</span>
|
266
267
|
|
267
268
|
<span class='kw'>case</span> <span class='id identifier rubyid_subcmd'>subcmd</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span>
|
268
|
-
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'
|
269
|
-
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'
|
270
|
-
<span class='kw'>end</span
|
269
|
+
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>add</span><span class='tstring_end'>'</span></span><span class='semicolon'>;</span> <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> Adding file \"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_subcmd'>subcmd</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>file</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span><span class='embexpr_end'>}</span><span class='tstring_content'>\"...</span><span class='tstring_end'>"</span></span>
|
270
|
+
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>rm</span><span class='tstring_end'>'</span></span><span class='semicolon'>;</span> <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> Removing file \"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_subcmd'>subcmd</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>file</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span><span class='embexpr_end'>}</span><span class='tstring_content'>\"...</span><span class='tstring_end'>"</span></span>
|
271
|
+
<span class='kw'>end</span>
|
272
|
+
</code></pre>
|
271
273
|
|
272
274
|
<p><span class='object_link'><a href="Como/Spec.html#program-class_method" title="Como::Spec.program (method)">Spec.program</a></span> method defines a program (command) with subcommands. The
|
273
275
|
author and date are provided as parameters, and the program and subcommand
|
274
276
|
options are defined in block.</p>
|
275
277
|
|
276
278
|
<p>The first <span class='object_link'><a href="Como/Spec.html#command-instance_method" title="Como::Spec#command (method)">Spec#command</a></span> (or <span class='object_link'><a href="Como/Spec.html#subcmd-instance_method" title="Como::Spec#subcmd (method)">Spec#subcmd</a></span>) method call defines the main
|
277
|
-
command (<span class='object_link'><a href="Como/Opt.html#main-class_method" title="Como::Opt.main (method)">Opt.main</a></span>) which represents the program. It has two
|
278
|
-
options (
|
279
|
+
command (<span class='object_link'><a href="Como/Opt.html#main-class_method" title="Como::Opt.main (method)">Opt.main</a></span>) which represents the program. It has two “subcmd”
|
280
|
+
options (“add” and “rm”).</p>
|
279
281
|
|
280
|
-
<p>The rest of the
|
282
|
+
<p>The rest of the “subcmd” methods define subcommands for the parent command.
|
281
283
|
This example includes one subcommand level, but multiple levels are
|
282
284
|
allowed.</p>
|
283
285
|
|
284
|
-
<p>The
|
286
|
+
<p>The “check” (or “checkRule”) method defines option combination
|
285
287
|
(<span class='object_link'><a href="Como/RuleCheck.html" title="Como::RuleCheck (class)">RuleCheck</a></span>) for the previous subcommand definition. In this case the
|
286
|
-
definition allows
|
287
|
-
|
288
|
+
definition allows “add” to have either the “-fo” option defined or
|
289
|
+
“password” and “username” in combination.</p>
|
288
290
|
|
289
291
|
<p>Main (root) commands can be referenced through</p>
|
290
292
|
|
@@ -292,21 +294,21 @@ definition allows "add" to have either the "-fo" option defined or
|
|
292
294
|
|
293
295
|
<p>or alternatively</p>
|
294
296
|
|
295
|
-
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'
|
297
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>como_subcmd</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span></code></pre>
|
296
298
|
|
297
299
|
<p>The subcommands can be referenced through <span class='object_link'><a href="Como/Opt.html#main-class_method" title="Como::Opt.main (method)">Opt.main</a></span> (etc.)</p>
|
298
300
|
|
299
|
-
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='period'>.</span><span class='id identifier rubyid_main'>main</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'
|
300
|
-
<span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'
|
301
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='period'>.</span><span class='id identifier rubyid_main'>main</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>add</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span>
|
302
|
+
<span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>como_subcmd</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>add</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span></code></pre>
|
301
303
|
|
302
304
|
<p>or directly from <span class='object_link'><a href="Como/Opt.html" title="Como::Opt (class)">Opt</a></span> if subcommand names do not collide:</p>
|
303
305
|
|
304
|
-
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'
|
306
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>add</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span></code></pre>
|
305
307
|
|
306
308
|
<p>The given subcommand can be accessed with <span class='object_link'><a href="Como/Opt.html#givenSubcmd-instance_method" title="Como::Opt#givenSubcmd (method)">Opt#givenSubcmd</a></span> method from
|
307
309
|
each parent command.</p>
|
308
310
|
|
309
|
-
<h3>Subcommand example executions</h3>
|
311
|
+
<h3 id="label-Subcommand+example+executions">Subcommand example executions</h3>
|
310
312
|
|
311
313
|
<p>Normal behavior would be achieved by executing:</p>
|
312
314
|
|
@@ -316,7 +318,7 @@ each parent command.</p>
|
|
316
318
|
|
317
319
|
<pre class="code ruby"><code class="ruby">Adding file "example"...</code></pre>
|
318
320
|
|
319
|
-
<p>The option combinations for
|
321
|
+
<p>The option combinations for “add” subcommand are automatically checked.
|
320
322
|
Thus executing:</p>
|
321
323
|
|
322
324
|
<pre class="code ruby"><code class="ruby">shell> como_subcmd add -f example</code></pre>
|
@@ -340,8 +342,8 @@ Thus executing:</p>
|
|
340
342
|
| | |--<password>
|
341
343
|
| | |--<username></code></pre>
|
342
344
|
|
343
|
-
<p>since the combination rule requires either
|
344
|
-
|
345
|
+
<p>since the combination rule requires either “-fo”, or both “password” and
|
346
|
+
“username”.</p>
|
345
347
|
|
346
348
|
<p>Help is automatically provided on each command level, thus these are both
|
347
349
|
valid.</p>
|
@@ -352,9 +354,9 @@ valid.</p>
|
|
352
354
|
|
353
355
|
<pre class="code ruby"><code class="ruby">shell> como_subcmd rm -h</code></pre>
|
354
356
|
|
355
|
-
<h1>Option specification</h1>
|
357
|
+
<h1 id="label-Option+specification">Option specification</h1>
|
356
358
|
|
357
|
-
<h2>Overview</h2>
|
359
|
+
<h2 id="label-Overview">Overview</h2>
|
358
360
|
|
359
361
|
<p>Option specification includes the minimum set of information required for
|
360
362
|
command line parsing. It is used to:</p>
|
@@ -372,41 +374,41 @@ command line parsing. It is used to:</p>
|
|
372
374
|
<p>Generate Usage Help printout.</p>
|
373
375
|
</li></ul>
|
374
376
|
|
375
|
-
<h2>Option types</h2>
|
377
|
+
<h2 id="label-Option+types">Option types</h2>
|
376
378
|
|
377
379
|
<p>The following types can be defined for the command line options:</p>
|
378
|
-
<dl class="rdoc-list"><dt>:subcmd
|
380
|
+
<dl class="rdoc-list label-list"><dt>:subcmd
|
379
381
|
<dd>
|
380
382
|
<p>Subcmd option. Subcmd specific options are provided separately.</p>
|
381
|
-
</dd><dt>:switch
|
383
|
+
</dd><dt>:switch
|
382
384
|
<dd>
|
383
385
|
<p>Single switch option (no arguments).</p>
|
384
|
-
</dd><dt>:single
|
386
|
+
</dd><dt>:single
|
385
387
|
<dd>
|
386
388
|
<p>Mandatory single argument option.</p>
|
387
|
-
</dd><dt>:multi
|
389
|
+
</dd><dt>:multi
|
388
390
|
<dd>
|
389
391
|
<p>Mandatory multiple argument option (one or many). Option values in array.</p>
|
390
|
-
</dd><dt>:opt_single
|
392
|
+
</dd><dt>:opt_single
|
391
393
|
<dd>
|
392
394
|
<p>Optional single argument option. Value is nil when option is not given.</p>
|
393
|
-
</dd><dt>:opt_multi
|
395
|
+
</dd><dt>:opt_multi
|
394
396
|
<dd>
|
395
397
|
<p>Optional multiple argument option (one or many). Option values in array.</p>
|
396
|
-
</dd><dt>:opt_any
|
398
|
+
</dd><dt>:opt_any
|
397
399
|
<dd>
|
398
400
|
<p>Optional multiple argument option (also none accepted). Option values in
|
399
401
|
array.</p>
|
400
|
-
</dd><dt>:default
|
402
|
+
</dd><dt>:default
|
401
403
|
<dd>
|
402
404
|
<p>Default option (no switch associated). Name and option String values can be
|
403
405
|
left out, since only the document string is used. Default option is
|
404
|
-
referred with
|
405
|
-
</dd><dt>:exclusive
|
406
|
+
referred with “:default” or “nil”.</p>
|
407
|
+
</dd><dt>:exclusive
|
406
408
|
<dd>
|
407
409
|
<p>Option that does not co-exist with other options. :exclusive can have
|
408
410
|
arguments as with :opt_any, however :exclusive is documented like :switch.</p>
|
409
|
-
</dd><dt>:silent
|
411
|
+
</dd><dt>:silent
|
410
412
|
<dd>
|
411
413
|
<p>Option that does not coexist with other options and is not displayed as an
|
412
414
|
option in Usage Help display. In effect a sub-option of :exclusive.</p>
|
@@ -416,21 +418,22 @@ option in Usage Help display. In effect a sub-option of :exclusive.</p>
|
|
416
418
|
|
417
419
|
<pre class="code ruby"><code class="ruby"><span class='lbracket'>[</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_mnemonic'>mnemonic</span><span class='comma'>,</span> <span class='id identifier rubyid_doc'>doc</span> <span class='rbracket'>]</span></code></pre>
|
418
420
|
|
419
|
-
<p
|
421
|
+
<p>“type” field is mandatory for all options.</p>
|
420
422
|
|
421
|
-
<p
|
423
|
+
<p>“name” field is also mandatory for all options. “mnemonic” can be left out,
|
422
424
|
but then option accepts only long option format.</p>
|
423
425
|
|
424
|
-
<p
|
426
|
+
<p>“:default” uses only “doc” and “:subcmd” doesn't use the “mnemonic”
|
427
|
+
field.</p>
|
425
428
|
|
426
|
-
<p
|
427
|
-
when an option specifier is found. This can be a problem if
|
428
|
-
option follows. The recommended solution is to use a
|
429
|
+
<p>“:multi”, “:opt_multi”, and “:opt_any” option arguments are terminated only
|
430
|
+
when an option specifier is found. This can be a problem if “:default”
|
431
|
+
option follows. The recommended solution is to use a “:silent” option that
|
429
432
|
can be used to terminate the argument list. For example:</p>
|
430
433
|
|
431
434
|
<pre class="code ruby"><code class="ruby">[ :silent, "terminator", "-", "The terminator." ],</code></pre>
|
432
435
|
|
433
|
-
<h2>Option specification method configuration</h2>
|
436
|
+
<h2 id="label-Option+specification+method+configuration">Option specification method configuration</h2>
|
434
437
|
|
435
438
|
<p>Option behavior can be controlled with several configuration options.</p>
|
436
439
|
|
@@ -442,47 +445,47 @@ to each subcommand separately to override the inherited config values.
|
|
442
445
|
Subcommand settings are not inherited, but apply only in the subcommand.</p>
|
443
446
|
|
444
447
|
<p>The usable configuration Hash keys:</p>
|
445
|
-
<dl class="rdoc-list"><dt>:autohelp
|
448
|
+
<dl class="rdoc-list label-list"><dt>:autohelp
|
446
449
|
<dd>
|
447
450
|
<p>Add help option automatically (default: true). Custom help option can be
|
448
451
|
provided and it can be made also visible to user.</p>
|
449
|
-
</dd><dt>:rulehelp
|
452
|
+
</dd><dt>:rulehelp
|
450
453
|
<dd>
|
451
454
|
<p>Include RuleCheck help to Usage Help (default: false).</p>
|
452
|
-
</dd><dt>:header
|
455
|
+
</dd><dt>:header
|
453
456
|
<dd>
|
454
457
|
<p>Header lines before standard usage printout.</p>
|
455
|
-
</dd><dt>:footer
|
458
|
+
</dd><dt>:footer
|
456
459
|
<dd>
|
457
460
|
<p>Footer lines after standard usage printout.</p>
|
458
|
-
</dd><dt>:subcheck
|
461
|
+
</dd><dt>:subcheck
|
459
462
|
<dd>
|
460
463
|
<p>Automatically check that a subcommand is provided (default: true).</p>
|
461
|
-
</dd><dt>:check_missing
|
464
|
+
</dd><dt>:check_missing
|
462
465
|
<dd>
|
463
466
|
<p>Check for missing arguments (default: true).</p>
|
464
|
-
</dd><dt>:check_invalid
|
467
|
+
</dd><dt>:check_invalid
|
465
468
|
<dd>
|
466
469
|
<p>Error for unknown options (default: true).</p>
|
467
|
-
</dd><dt>:tab
|
470
|
+
</dd><dt>:tab
|
468
471
|
<dd>
|
469
472
|
<p>Tab stop column for option documentation (default: 12).</p>
|
470
|
-
</dd><dt>:help_exit
|
473
|
+
</dd><dt>:help_exit
|
471
474
|
<dd>
|
472
475
|
<p>Exit program if help displayed (default: true).</p>
|
473
|
-
</dd><dt>:copyright
|
476
|
+
</dd><dt>:copyright
|
474
477
|
<dd>
|
475
478
|
<p>Display copyright/author in usage printout (default: true).</p>
|
476
479
|
</dd></dl>
|
477
480
|
|
478
|
-
<h1>Option referencing</h1>
|
481
|
+
<h1 id="label-Option+referencing">Option referencing</h1>
|
479
482
|
|
480
|
-
<h2>Existence and values</h2>
|
483
|
+
<h2 id="label-Existence+and+values">Existence and values</h2>
|
481
484
|
|
482
485
|
<p>Opt class includes the parsed option values. All options can be tested
|
483
486
|
whether they are specified on the command line using:</p>
|
484
487
|
|
485
|
-
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'
|
488
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>name</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_given'>given</span></code></pre>
|
486
489
|
|
487
490
|
<p>The <span class='object_link'><a href="Como/Opt.html#given-instance_method" title="Como::Opt#given (method)">Opt#given</a></span> method takes optionally a block argument. When block
|
488
491
|
argument is used, the block is supplied with option value and the block is
|
@@ -490,38 +493,39 @@ executed if the option has been set (See: <span class='object_link'><a href="Com
|
|
490
493
|
|
491
494
|
<p>Provided value is returned by:</p>
|
492
495
|
|
493
|
-
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'
|
496
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>name</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span></code></pre>
|
494
497
|
|
495
|
-
<p>For
|
498
|
+
<p>For “:switch” type it is true/false value and for the other types a String
|
496
499
|
or an Array of Strings.</p>
|
497
500
|
|
498
501
|
<p>If an option takes multiple arguments, the value for the option is an
|
499
502
|
Array. The values can be iterated simply by:</p>
|
500
503
|
|
501
|
-
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'
|
504
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>files</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_val'>val</span><span class='op'>|</span>
|
502
505
|
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_val'>val</span>
|
503
|
-
<span class='kw'>end</span
|
506
|
+
<span class='kw'>end</span>
|
507
|
+
</code></pre>
|
504
508
|
|
505
|
-
<p>Short syntax for value referencing is performed with unary operator
|
509
|
+
<p>Short syntax for value referencing is performed with unary operator “~”.
|
506
510
|
Thus</p>
|
507
511
|
|
508
|
-
<pre class="code ruby"><code class="ruby"><span class='op'>~</span><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'
|
512
|
+
<pre class="code ruby"><code class="ruby"><span class='op'>~</span><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>files</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span></code></pre>
|
509
513
|
|
510
514
|
<p>is equal to</p>
|
511
515
|
|
512
|
-
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'
|
516
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>files</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span></code></pre>
|
513
517
|
|
514
|
-
<p>With
|
518
|
+
<p>With “:opt_any” type, the user should first check if the option was given:</p>
|
515
519
|
|
516
|
-
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'
|
520
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>many_files_or_none</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_given'>given</span></code></pre>
|
517
521
|
|
518
522
|
<p>Then check how many arguments where given:</p>
|
519
523
|
|
520
|
-
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'
|
524
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>many_files_or_none</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span></code></pre>
|
521
525
|
|
522
526
|
<p>And finally decide what to do.</p>
|
523
527
|
|
524
|
-
<h2>Options including parameters</h2>
|
528
|
+
<h2 id="label-Options+including+parameters">Options including parameters</h2>
|
525
529
|
|
526
530
|
<p>Sometimes it is convenient for the program to use an option to include
|
527
531
|
multiple parameter settings. These settings can be parsed and mapped to a
|
@@ -530,29 +534,30 @@ example with option:</p>
|
|
530
534
|
|
531
535
|
<pre class="code ruby"><code class="ruby">--set rounds=10 length=5</code></pre>
|
532
536
|
|
533
|
-
<p>Como can be used extract the parameter values with the
|
537
|
+
<p>Como can be used extract the parameter values with the “params” method:</p>
|
534
538
|
|
535
|
-
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'
|
539
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>Opt</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>set</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_params'>params</span></code></pre>
|
536
540
|
|
537
541
|
<p>And a Hash is returned:</p>
|
538
542
|
|
539
|
-
<pre class="code ruby"><code class="ruby"><span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'
|
543
|
+
<pre class="code ruby"><code class="ruby"><span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>rounds</span><span class='tstring_end'>'</span></span> <span class='op'>=></span> <span class='int'>10</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>length</span><span class='tstring_end'>'</span></span> <span class='op'>=></span> <span class='int'>5</span> <span class='rbrace'>}</span>
|
544
|
+
</code></pre>
|
540
545
|
|
541
|
-
<h2>Subcommand options</h2>
|
546
|
+
<h2 id="label-Subcommand+options">Subcommand options</h2>
|
542
547
|
|
543
548
|
<p>The given subcommand for the parent command is return by <span class='object_link'><a href="Como/Opt.html#givenSubcmd-instance_method" title="Como::Opt#givenSubcmd (method)">Opt#givenSubcmd</a></span>.
|
544
549
|
Commonly the program creator should just check directly which subcommand
|
545
550
|
has been selected and check for any subcommand options set. For example:</p>
|
546
551
|
|
547
|
-
<pre class="code ruby"><code class="ruby">if Opt[
|
552
|
+
<pre class="code ruby"><code class="ruby">if Opt['como_subcmd']['add'].given
|
548
553
|
...</code></pre>
|
549
554
|
|
550
|
-
<h2>Program external options</h2>
|
555
|
+
<h2 id="label-Program+external+options">Program external options</h2>
|
551
556
|
|
552
|
-
<p>If the user gives the
|
557
|
+
<p>If the user gives the “–” option (double-dash), the arguments after that
|
553
558
|
option are returned as an Array with <span class='object_link'><a href="Como/Opt.html#external-class_method" title="Como::Opt.external (method)">Opt.external</a></span>.</p>
|
554
559
|
|
555
|
-
<h1>Option combination checks</h1>
|
560
|
+
<h1 id="label-Option+combination+checks">Option combination checks</h1>
|
556
561
|
|
557
562
|
<p>Como provides a facility to create relations between options using
|
558
563
|
RuleCheck DSL. This is needed since sometimes options have to be used in
|
@@ -560,38 +565,38 @@ combination to make sense for the program. Also options might be mutually
|
|
560
565
|
exclusive.</p>
|
561
566
|
|
562
567
|
<p>The following rules can be used (in combination):</p>
|
563
|
-
<dl class="rdoc-list"><dt>all
|
568
|
+
<dl class="rdoc-list label-list"><dt>all
|
564
569
|
<dd>
|
565
570
|
<p>All options in the list.</p>
|
566
|
-
</dd><dt>one
|
571
|
+
</dd><dt>one
|
567
572
|
<dd>
|
568
573
|
<p>One and only one from the list.</p>
|
569
|
-
</dd><dt>any
|
574
|
+
</dd><dt>any
|
570
575
|
<dd>
|
571
576
|
<p>At least one of the list is given.</p>
|
572
|
-
</dd><dt>none
|
577
|
+
</dd><dt>none
|
573
578
|
<dd>
|
574
579
|
<p>No options are required.</p>
|
575
|
-
</dd><dt>inv
|
580
|
+
</dd><dt>inv
|
576
581
|
<dd>
|
577
582
|
<p>Logical negation for existence.</p>
|
578
|
-
</dd><dt>incr
|
583
|
+
</dd><dt>incr
|
579
584
|
<dd>
|
580
585
|
<p>Incremental options in order i.e. have to have previous to have later.</p>
|
581
|
-
</dd><dt>follow
|
586
|
+
</dd><dt>follow
|
582
587
|
<dd>
|
583
588
|
<p>Incremental options in order i.e. have to have all later if had first.</p>
|
584
|
-
</dd><dt>meh
|
589
|
+
</dd><dt>meh
|
585
590
|
<dd>
|
586
591
|
<p>Dont care, always succeeds.</p>
|
587
592
|
</dd></dl>
|
588
593
|
|
589
594
|
<p>Examples can be found above.</p>
|
590
595
|
|
591
|
-
<h1>Customization</h1>
|
596
|
+
<h1 id="label-Customization">Customization</h1>
|
592
597
|
|
593
598
|
<p>A Como user specific customization file can be referenced through the
|
594
|
-
|
599
|
+
“COMO” environment variable. If environment variable “COMO” is defined, the
|
595
600
|
referenced file is read in as Ruby file as a last phase when Como is loaded
|
596
601
|
from the program (require). Proposed naming convention for the
|
597
602
|
customization is:</p>
|
@@ -614,15 +619,16 @@ parameter names as symbols.</p>
|
|
614
619
|
<span class='comment'># Get default config for options.
|
615
620
|
</span> <span class='id identifier rubyid_config'>config</span> <span class='op'>=</span> <span class='const'>Como</span><span class='op'>::</span><span class='const'>Opt</span><span class='period'>.</span><span class='id identifier rubyid_configGet'>configGet</span>
|
616
621
|
|
617
|
-
<span class='comment'># Disable
|
622
|
+
<span class='comment'># Disable 'copyright' lines from usage.
|
618
623
|
</span> <span class='id identifier rubyid_config'>config</span><span class='lbracket'>[</span> <span class='symbol'>:copyright</span> <span class='rbracket'>]</span> <span class='op'>=</span> <span class='kw'>false</span>
|
619
624
|
|
620
625
|
<span class='comment'># Test if "Spec.command" is the entry method (it has arg named "prog").
|
621
626
|
</span> <span class='kw'>if</span> <span class='id identifier rubyid_args'>args</span><span class='lbracket'>[</span> <span class='symbol'>:prog</span> <span class='rbracket'>]</span>
|
622
627
|
<span class='comment'># Place a custom header for all programs.
|
623
|
-
</span> <span class='id identifier rubyid_config'>config</span><span class='lbracket'>[</span> <span class='symbol'>:header</span> <span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\nProgram \"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_args'>args</span><span class='lbracket'>[</span> <span class='symbol'>:prog</span> <span class='rbracket'>]</span><span class='
|
628
|
+
</span> <span class='id identifier rubyid_config'>config</span><span class='lbracket'>[</span> <span class='symbol'>:header</span> <span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\nProgram \"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_args'>args</span><span class='lbracket'>[</span> <span class='symbol'>:prog</span> <span class='rbracket'>]</span><span class='embexpr_end'>}</span><span class='tstring_content'>\" is ...\n\n</span><span class='tstring_end'>"</span></span>
|
624
629
|
<span class='kw'>end</span>
|
625
|
-
<span class='kw'>end</span
|
630
|
+
<span class='kw'>end</span>
|
631
|
+
</code></pre>
|
626
632
|
|
627
633
|
<p>There is no predefined use cases for post-hook. Post-hook is passed the
|
628
634
|
<span class='object_link'><a href="Como/Opt.html#main-class_method" title="Como::Opt.main (method)">Opt.main</a></span> as parameter.</p>
|
@@ -667,7 +673,7 @@ of the internal workings of Como is required though.</p>
|
|
667
673
|
<dt id="VERSION-constant" class="">VERSION =
|
668
674
|
|
669
675
|
</dt>
|
670
|
-
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0.1.
|
676
|
+
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0.1.5</span><span class='tstring_end'>"</span></span></pre></dd>
|
671
677
|
|
672
678
|
</dl>
|
673
679
|
|
@@ -704,7 +710,7 @@ of the internal workings of Como is required though.</p>
|
|
704
710
|
|
705
711
|
|
706
712
|
<span class="summary_desc"><div class='inline'>
|
707
|
-
<p>Set
|
713
|
+
<p>Set “postHook” routine.</p>
|
708
714
|
</div></span>
|
709
715
|
|
710
716
|
</li>
|
@@ -728,7 +734,7 @@ of the internal workings of Como is required though.</p>
|
|
728
734
|
|
729
735
|
|
730
736
|
<span class="summary_desc"><div class='inline'>
|
731
|
-
<p>Set
|
737
|
+
<p>Set “preHook” routine.</p>
|
732
738
|
</div></span>
|
733
739
|
|
734
740
|
</li>
|
@@ -777,7 +783,7 @@ of the internal workings of Como is required though.</p>
|
|
777
783
|
</h3><div class="docstring">
|
778
784
|
<div class="discussion">
|
779
785
|
|
780
|
-
<p>Set
|
786
|
+
<p>Set “postHook” routine.</p>
|
781
787
|
|
782
788
|
|
783
789
|
</div>
|
@@ -818,7 +824,7 @@ of the internal workings of Como is required though.</p>
|
|
818
824
|
</h3><div class="docstring">
|
819
825
|
<div class="discussion">
|
820
826
|
|
821
|
-
<p>Set
|
827
|
+
<p>Set “preHook” routine.</p>
|
822
828
|
|
823
829
|
|
824
830
|
</div>
|
@@ -882,9 +888,9 @@ of the internal workings of Como is required though.</p>
|
|
882
888
|
</div>
|
883
889
|
|
884
890
|
<div id="footer">
|
885
|
-
Generated on
|
891
|
+
Generated on Mon Apr 20 18:44:03 2015 by
|
886
892
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
887
|
-
0.8.6
|
893
|
+
0.8.7.6 (ruby-2.1.2).
|
888
894
|
</div>
|
889
895
|
|
890
896
|
</body>
|