cli 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +5 -7
  3. data/Gemfile.lock +29 -37
  4. data/README.md +17 -18
  5. data/Rakefile +1 -28
  6. data/cli.gemspec +14 -84
  7. data/rdoc/CLI/Arguments.html +178 -0
  8. data/rdoc/CLI/DSL/Argument.html +200 -0
  9. data/rdoc/CLI/DSL/Arguments.html +172 -0
  10. data/rdoc/CLI/DSL/Base.html +154 -0
  11. data/rdoc/CLI/DSL/Cast.html +152 -0
  12. data/rdoc/CLI/DSL/Description.html +150 -0
  13. data/rdoc/CLI/DSL/Input.html +143 -0
  14. data/rdoc/CLI/DSL/MultiDefault.html +151 -0
  15. data/rdoc/CLI/DSL/Option.html +143 -0
  16. data/rdoc/CLI/DSL/Options.html +142 -0
  17. data/rdoc/CLI/DSL/Switch.html +267 -0
  18. data/rdoc/CLI/DSL/Value.html +238 -0
  19. data/rdoc/CLI/DSL.html +91 -0
  20. data/rdoc/CLI/Options.html +200 -0
  21. data/rdoc/CLI/ParserError/ArgumentNameSpecifiedTwice.html +138 -0
  22. data/rdoc/CLI/ParserError/LongNameSpecifiedTwiceError.html +138 -0
  23. data/rdoc/CLI/ParserError/MultipleArgumentsSpecifierError.html +138 -0
  24. data/rdoc/CLI/ParserError/NameArgumetNotSymbolError.html +138 -0
  25. data/rdoc/CLI/ParserError/OptionsArgumentNotHashError.html +138 -0
  26. data/rdoc/CLI/ParserError/ShortNameIsInvalidError.html +138 -0
  27. data/rdoc/CLI/ParserError/ShortNameNotSymbolError.html +138 -0
  28. data/rdoc/CLI/ParserError/ShortNameSpecifiedTwiceError.html +138 -0
  29. data/rdoc/CLI/ParserError.html +97 -0
  30. data/rdoc/CLI/ParsingError/CastError.html +138 -0
  31. data/rdoc/CLI/ParsingError/MandatoryArgumentNotSpecifiedError.html +138 -0
  32. data/rdoc/CLI/ParsingError/MandatoryOptionsNotSpecifiedError.html +138 -0
  33. data/rdoc/CLI/ParsingError/MissingOptionValueError.html +138 -0
  34. data/rdoc/CLI/ParsingError/UnknownSwitchError.html +138 -0
  35. data/rdoc/CLI/ParsingError/UsageError.html +97 -0
  36. data/rdoc/CLI/ParsingError.html +97 -0
  37. data/rdoc/CLI/Switches.html +306 -0
  38. data/rdoc/CLI/Values.html +202 -0
  39. data/rdoc/CLI.html +652 -0
  40. data/rdoc/README_md.html +553 -0
  41. data/rdoc/created.rid +7 -0
  42. data/rdoc/css/fonts.css +167 -0
  43. data/rdoc/css/rdoc.css +639 -0
  44. data/rdoc/fonts/Lato-Light.ttf +0 -0
  45. data/rdoc/fonts/Lato-LightItalic.ttf +0 -0
  46. data/rdoc/fonts/Lato-Regular.ttf +0 -0
  47. data/rdoc/fonts/Lato-RegularItalic.ttf +0 -0
  48. data/rdoc/fonts/SourceCodePro-Bold.ttf +0 -0
  49. data/rdoc/fonts/SourceCodePro-Regular.ttf +0 -0
  50. data/rdoc/images/add.png +0 -0
  51. data/rdoc/images/arrow_up.png +0 -0
  52. data/rdoc/images/brick.png +0 -0
  53. data/rdoc/images/brick_link.png +0 -0
  54. data/rdoc/images/bug.png +0 -0
  55. data/rdoc/images/bullet_black.png +0 -0
  56. data/rdoc/images/bullet_toggle_minus.png +0 -0
  57. data/rdoc/images/bullet_toggle_plus.png +0 -0
  58. data/rdoc/images/date.png +0 -0
  59. data/rdoc/images/delete.png +0 -0
  60. data/rdoc/images/find.png +0 -0
  61. data/rdoc/images/loadingAnimation.gif +0 -0
  62. data/rdoc/images/macFFBgHack.png +0 -0
  63. data/rdoc/images/package.png +0 -0
  64. data/rdoc/images/page_green.png +0 -0
  65. data/rdoc/images/page_white_text.png +0 -0
  66. data/rdoc/images/page_white_width.png +0 -0
  67. data/rdoc/images/plugin.png +0 -0
  68. data/rdoc/images/ruby.png +0 -0
  69. data/rdoc/images/tag_blue.png +0 -0
  70. data/rdoc/images/tag_green.png +0 -0
  71. data/rdoc/images/transparent.png +0 -0
  72. data/rdoc/images/wrench.png +0 -0
  73. data/rdoc/images/wrench_orange.png +0 -0
  74. data/rdoc/images/zoom.png +0 -0
  75. data/rdoc/index.html +120 -0
  76. data/rdoc/js/darkfish.js +84 -0
  77. data/rdoc/js/navigation.js +105 -0
  78. data/rdoc/js/navigation.js.gz +0 -0
  79. data/rdoc/js/search.js +110 -0
  80. data/rdoc/js/search_index.js +1 -0
  81. data/rdoc/js/search_index.js.gz +0 -0
  82. data/rdoc/js/searcher.js +229 -0
  83. data/rdoc/js/searcher.js.gz +0 -0
  84. data/rdoc/table_of_contents.html +533 -0
  85. data/spec/argument_spec.rb +104 -105
  86. data/spec/cli_spec.rb +27 -28
  87. data/spec/conflict_reporting_spec.rb +16 -17
  88. data/spec/option_spec.rb +60 -61
  89. data/spec/separator_spec.rb +19 -20
  90. data/spec/stdin_spec.rb +13 -14
  91. data/spec/switch_spec.rb +15 -16
  92. data/spec/usage_spec.rb +80 -81
  93. metadata +91 -139
  94. data/.document +0 -5
  95. data/.rspec +0 -1
  96. data/VERSION +0 -1
  97. data/features/cli.feature +0 -9
  98. data/features/step_definitions/cli_steps.rb +0 -0
  99. data/features/support/env.rb +0 -13
@@ -0,0 +1,553 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta charset="UTF-8">
6
+
7
+ <title>README - 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="file">
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
+ <div class="nav-section">
58
+ <h3>Table of Contents</h3>
59
+
60
+ <ul class="link-list" role="directory">
61
+ <li><a href="#label-CLI">CLI</a>
62
+ <li><a href="#label-Installing">Installing</a>
63
+ <li><a href="#label-Examples">Examples</a>
64
+ <li><a href="#label-HTTPClient+example">HTTPClient example</a>
65
+ <li><a href="#label-Sinatra+server+example">Sinatra server example</a>
66
+ <li><a href="#label-Statistic+data+processor+example">Statistic data processor example</a>
67
+ <li><a href="#label-Ls+like+utility">Ls like utility</a>
68
+ <li><a href="#label-Usage">Usage</a>
69
+ <li><a href="#label-23parse+method"><code>#parse</code> method</a>
70
+ <li><a href="#label-23parse-21+method"><code>#parse!</code> method</a>
71
+ <li><a href="#label-Parser+behavior+specifiers">Parser behavior specifiers</a>
72
+ <li><a href="#label-description+-27string-27">description ‘string’</a>
73
+ <li><a href="#label-version+-27string-27">version ‘string’</a>
74
+ <li><a href="#label-switch+-3Aname+-5B-2C+options+hash-5D">switch :name [, options hash]</a>
75
+ <li><a href="#label-option+-3Aname+-5B-2C+options+hash-5D">option :name [, options hash]</a>
76
+ <li><a href="#label-options+-3Aname+-5B-2C+options+hash-5D">options :name [, options hash]</a>
77
+ <li><a href="#label-argument+-3Aname+-5B-2Coptions+hash-5D">argument :name [,options hash]</a>
78
+ <li><a href="#label-arguments+-3Aname+-5B-2Coptions+hash-5D">arguments :name [,options hash]</a>
79
+ <li><a href="#label-stdin+-3Aname-2C+-5Boptions+hash-5D">stdin :name, [options hash]</a>
80
+ <li><a href="#label-Contributing+to+CLI">Contributing to CLI</a>
81
+ <li><a href="#label-Copyright">Copyright</a>
82
+ </ul>
83
+ </div>
84
+
85
+
86
+ <div id="project-metadata">
87
+
88
+ <div id="fileindex-section" class="nav-section">
89
+ <h3>Pages</h3>
90
+
91
+ <ul class="link-list">
92
+ <li><a href="./README_md.html">README</a>
93
+ </ul>
94
+ </div>
95
+
96
+ </div>
97
+ </nav>
98
+
99
+ <main role="main" aria-label="Page README.md">
100
+
101
+ <h1 id="label-CLI"><a href="CLI.html"><code>CLI</code></a><span><a href="#label-CLI">&para;</a> <a href="#top">&uarr;</a></span></h1>
102
+
103
+ <p>Command Line Interface gem allows you to quickly specify command argument parser that will automatically generate usage, handle stdin, switches, options and arguments with default values and value casting.</p>
104
+
105
+ <h2 id="label-Installing">Installing<span><a href="#label-Installing">&para;</a> <a href="#top">&uarr;</a></span></h2>
106
+
107
+ <pre class="ruby"><span class="ruby-identifier">gem</span> <span class="ruby-identifier">install</span> <span class="ruby-identifier">cli</span>
108
+ </pre>
109
+
110
+ <h2 id="label-Examples">Examples<span><a href="#label-Examples">&para;</a> <a href="#top">&uarr;</a></span></h2>
111
+
112
+ <h3 id="label-HTTPClient+example">HTTPClient example<span><a href="#label-HTTPClient+example">&para;</a> <a href="#top">&uarr;</a></span></h3>
113
+
114
+ <p>The following example shows basic usage of the <a href="CLI.html"><code>CLI</code></a> gem. It will use HTTPClient to connect to server that address and port can be specified with <code>--server</code> and <code>--port</code> switches. It expects at least one argument specifying the URL (that needs to start with <code>/</code>) and optional set of POST arguments.</p>
115
+
116
+ <pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;rubygems&#39;</span>
117
+ <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;cli&#39;</span>
118
+ <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;httpclient&#39;</span>
119
+
120
+ <span class="ruby-identifier">settings</span> = <span class="ruby-constant">CLI</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">do</span>
121
+ <span class="ruby-identifier">option</span> <span class="ruby-value">:server</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;server address&#39;</span>, <span class="ruby-value">:default</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;www.google.com&#39;</span>
122
+ <span class="ruby-identifier">option</span> <span class="ruby-value">:port</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;server port&#39;</span>, <span class="ruby-value">:cast</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-constant">Integer</span>, <span class="ruby-value">:default</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">80</span>
123
+ <span class="ruby-identifier">argument</span> <span class="ruby-value">:url</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;URL to GET or POST to if arguments are given&#39;</span>
124
+ <span class="ruby-identifier">arguments</span> <span class="ruby-value">:post_arguments</span>, <span class="ruby-value">:required</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-keyword">false</span>
125
+ <span class="ruby-keyword">end</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">settings</span><span class="ruby-operator">|</span>
126
+ <span class="ruby-identifier">fail</span> <span class="ruby-node">&quot;invalid URL &#39;#{settings.url}&#39;, URL has to start with &#39;/&#39;&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">settings</span>.<span class="ruby-identifier">url</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/^\//</span>
127
+ <span class="ruby-keyword">end</span>
128
+
129
+ <span class="ruby-identifier">c</span> = <span class="ruby-constant">HTTPClient</span>.<span class="ruby-identifier">new</span>
130
+
131
+ <span class="ruby-keyword">begin</span>
132
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">settings</span>.<span class="ruby-identifier">post_arguments</span>.<span class="ruby-identifier">empty?</span>
133
+ <span class="ruby-identifier">puts</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">get_async</span>(<span class="ruby-node">&quot;http://#{settings.server}:#{settings.port}#{settings.url}&quot;</span>).<span class="ruby-identifier">pop</span>.<span class="ruby-identifier">content</span>.<span class="ruby-identifier">read</span>
134
+ <span class="ruby-keyword">else</span>
135
+ <span class="ruby-identifier">puts</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">post_async</span>(<span class="ruby-node">&quot;http://#{settings.server}:#{settings.port}#{settings.url}&quot;</span>, <span class="ruby-identifier">settings</span>.<span class="ruby-identifier">post_arguments</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">&quot;\n&quot;</span>)).<span class="ruby-identifier">pop</span>.<span class="ruby-identifier">content</span>.<span class="ruby-identifier">read</span>
136
+ <span class="ruby-keyword">end</span>
137
+ <span class="ruby-keyword">rescue</span> <span class="ruby-constant">SocketError</span>, <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ECONNREFUSED</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">e</span>
138
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Failed to connect: #{e}&quot;</span>
139
+ <span class="ruby-keyword">end</span>
140
+ </pre>
141
+
142
+ <p>Example usage with default server:</p>
143
+
144
+ <pre>examples/httpclient /index.html</pre>
145
+
146
+ <p>The output will contain Google website.</p>
147
+
148
+ <p>Using different server:</p>
149
+
150
+ <pre>examples/httpclient --server ibm.com /index.html</pre>
151
+
152
+ <p>When run without arguments:</p>
153
+
154
+ <pre class="ruby"><span class="ruby-identifier">examples</span><span class="ruby-operator">/</span><span class="ruby-identifier">httpclient</span>
155
+ </pre>
156
+
157
+ <p>The following message will be printed and the program will exit (status 42):</p>
158
+
159
+ <pre>Error: mandatory argument &#39;url&#39; not given
160
+ Usage: httpclient [switches|options] [--] url [post-arguments*]
161
+ Switches:
162
+ --help (-h) - display this help message
163
+ Options:
164
+ --server [www.google.com] - server address
165
+ --port [80] - server port
166
+ Arguments:
167
+ url - URL to GET or POST to if arguments are given
168
+ post-arguments* (optional)</pre>
169
+
170
+ <p>When used with command that does not start with <code>/</code>:</p>
171
+
172
+ <pre>examples/httpclient test</pre>
173
+
174
+ <p>It will print the following message and exit:</p>
175
+
176
+ <pre>Error: invalid URL &#39;test&#39;, URL has to start with &#39;/&#39;
177
+ Usage: httpclient [switches|options] [--] url [post-arguments*]
178
+ Switches:
179
+ --help (-h) - display this help message
180
+ Options:
181
+ --server [www.google.com] - server address
182
+ --port [80] - server port
183
+ Arguments:
184
+ url - URL to GET or POST to if arguments are given
185
+ post-arguments* (optional)</pre>
186
+
187
+ <h3 id="label-Sinatra+server+example">Sinatra server example<span><a href="#label-Sinatra+server+example">&para;</a> <a href="#top">&uarr;</a></span></h3>
188
+
189
+ <pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;rubygems&#39;</span>
190
+ <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;cli&#39;</span>
191
+ <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;ip&#39;</span>
192
+
193
+ <span class="ruby-identifier">settings</span> = <span class="ruby-constant">CLI</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">do</span>
194
+ <span class="ruby-identifier">description</span> <span class="ruby-string">&#39;Example CLI usage for Sinatra server application&#39;</span>
195
+ <span class="ruby-identifier">version</span> <span class="ruby-string">&quot;1.0.0&quot;</span>
196
+ <span class="ruby-identifier">switch</span> <span class="ruby-value">:no_bind</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Do not bind to TCP socket - useful with -s fastcgi option&quot;</span>
197
+ <span class="ruby-identifier">switch</span> <span class="ruby-value">:no_logging</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Disable logging&quot;</span>
198
+ <span class="ruby-identifier">switch</span> <span class="ruby-value">:debug</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Enable debugging&quot;</span>
199
+ <span class="ruby-identifier">switch</span> <span class="ruby-value">:no_optimization</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Disable size hinting and related optimization (loading, prescaling)&quot;</span>
200
+ <span class="ruby-identifier">option</span> <span class="ruby-value">:bind</span>, <span class="ruby-value">:short</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">:b</span>, <span class="ruby-value">:default</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;127.0.0.1&#39;</span>, <span class="ruby-value">:cast</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-constant">IP</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;HTTP server bind address - use 0.0.0.0 to bind to all interfaces&quot;</span>
201
+ <span class="ruby-identifier">option</span> <span class="ruby-value">:port</span>, <span class="ruby-value">:short</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">:p</span>, <span class="ruby-value">:default</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">3100</span>, <span class="ruby-value">:cast</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-constant">Integer</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;HTTP server TCP port&quot;</span>
202
+ <span class="ruby-identifier">option</span> <span class="ruby-value">:server</span>, <span class="ruby-value">:short</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">:s</span>, <span class="ruby-value">:default</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;mongrel&#39;</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Rack server handler like thin, mongrel, webrick, fastcgi etc.&quot;</span>
203
+ <span class="ruby-identifier">option</span> <span class="ruby-value">:limit_memory</span>, <span class="ruby-value">:default</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">128</span><span class="ruby-operator">*</span><span class="ruby-value">1024</span><span class="ruby-operator">**</span><span class="ruby-value">2</span>, <span class="ruby-value">:cast</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-constant">Integer</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Image cache heap memory size limit in bytes&quot;</span>
204
+ <span class="ruby-identifier">option</span> <span class="ruby-value">:limit_map</span>, <span class="ruby-value">:default</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">256</span><span class="ruby-operator">*</span><span class="ruby-value">1024</span><span class="ruby-operator">**</span><span class="ruby-value">2</span>, <span class="ruby-value">:cast</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-constant">Integer</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Image cache memory mapped file size limit in bytes - used when heap memory limit is used up&quot;</span>
205
+ <span class="ruby-identifier">option</span> <span class="ruby-value">:limit_disk</span>, <span class="ruby-value">:default</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">0</span>, <span class="ruby-value">:cast</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-constant">Integer</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Image cache temporary file size limit in bytes - used when memory mapped file limit is used up&quot;</span>
206
+ <span class="ruby-keyword">end</span>.<span class="ruby-identifier">parse!</span>
207
+
208
+ <span class="ruby-comment"># use to set sinatra settings</span>
209
+ <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;sinatra/base&#39;</span>
210
+
211
+ <span class="ruby-identifier">sinatra</span> = <span class="ruby-constant">Sinatra</span>.<span class="ruby-identifier">new</span>
212
+
213
+ <span class="ruby-identifier">sinatra</span>.<span class="ruby-identifier">set</span> <span class="ruby-value">:environment</span>, <span class="ruby-string">&#39;production&#39;</span>
214
+ <span class="ruby-identifier">sinatra</span>.<span class="ruby-identifier">set</span> <span class="ruby-value">:server</span>, <span class="ruby-identifier">settings</span>.<span class="ruby-identifier">server</span>
215
+ <span class="ruby-identifier">sinatra</span>.<span class="ruby-identifier">set</span> <span class="ruby-value">:lock</span>, <span class="ruby-keyword">true</span>
216
+ <span class="ruby-identifier">sinatra</span>.<span class="ruby-identifier">set</span> <span class="ruby-value">:boundary</span>, <span class="ruby-string">&quot;thumbnail image data&quot;</span>
217
+ <span class="ruby-identifier">sinatra</span>.<span class="ruby-identifier">set</span> <span class="ruby-value">:logging</span>, (<span class="ruby-keyword">not</span> <span class="ruby-identifier">settings</span>.<span class="ruby-identifier">no_logging</span>)
218
+ <span class="ruby-identifier">sinatra</span>.<span class="ruby-identifier">set</span> <span class="ruby-value">:debug</span>, <span class="ruby-identifier">settings</span>.<span class="ruby-identifier">debug</span>
219
+ <span class="ruby-identifier">sinatra</span>.<span class="ruby-identifier">set</span> <span class="ruby-value">:optimization</span>, (<span class="ruby-keyword">not</span> <span class="ruby-identifier">settings</span>.<span class="ruby-identifier">no_optimization</span>)
220
+ <span class="ruby-identifier">sinatra</span>.<span class="ruby-identifier">set</span> <span class="ruby-value">:limit_memory</span>, <span class="ruby-identifier">settings</span>.<span class="ruby-identifier">limit_memory</span>
221
+ <span class="ruby-identifier">sinatra</span>.<span class="ruby-identifier">set</span> <span class="ruby-value">:limit_map</span>, <span class="ruby-identifier">settings</span>.<span class="ruby-identifier">limit_map</span>
222
+ <span class="ruby-identifier">sinatra</span>.<span class="ruby-identifier">set</span> <span class="ruby-value">:limit_disk</span>, <span class="ruby-identifier">settings</span>.<span class="ruby-identifier">limit_disk</span>
223
+
224
+ <span class="ruby-comment"># set up your application</span>
225
+
226
+ <span class="ruby-identifier">sinatra</span>.<span class="ruby-identifier">run!</span>
227
+ </pre>
228
+
229
+ <p>To see help message use <code>--help</code> or <code>-h</code> anywhere on the command line:</p>
230
+
231
+ <pre>examples/sinatra --help</pre>
232
+
233
+ <p>Example help message:</p>
234
+
235
+ <pre>Usage: sinatra [switches|options]
236
+ Example CLI usage for Sinatra server application
237
+ Switches:
238
+ --no-bind - Do not bind to TCP socket - useful with -s fastcgi option
239
+ --no-logging - Disable logging
240
+ --debug - Enable debugging
241
+ --no-optimization - Disable size hinting and related optimization (loading, prescaling)
242
+ --help (-h) - display this help message
243
+ --version - display version string
244
+ Options:
245
+ --bind (-b) [127.0.0.1] - HTTP server bind address - use 0.0.0.0 to bind to all interfaces
246
+ --port (-p) [3100] - HTTP server TCP port
247
+ --server (-s) [mongrel] - Rack server handler like thin, mongrel, webrick, fastcgi etc.
248
+ --limit-memory [134217728] - Image cache heap memory size limit in bytes
249
+ --limit-map [268435456] - Image cache memory mapped file size limit in bytes - used when heap memory limit is used up
250
+ --limit-disk [0] - Image cache temporary file size limit in bytes - used when memory mapped file limit is used up</pre>
251
+
252
+ <p>To see version string use <code>--version</code></p>
253
+
254
+ <pre>examples/sinatra --version</pre>
255
+
256
+ <p>Example version output:</p>
257
+
258
+ <pre class="ruby"><span class="ruby-identifier">sinatra</span> <span class="ruby-identifier">version</span> <span class="ruby-string">&quot;0.0.4&quot;</span>
259
+ </pre>
260
+
261
+ <h3 id="label-Statistic+data+processor+example">Statistic data processor example<span><a href="#label-Statistic+data+processor+example">&para;</a> <a href="#top">&uarr;</a></span></h3>
262
+
263
+ <pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;rubygems&#39;</span>
264
+ <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;cli&#39;</span>
265
+ <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;pathname&#39;</span>
266
+ <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;yaml&#39;</span>
267
+
268
+ <span class="ruby-identifier">settings</span> = <span class="ruby-constant">CLI</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">do</span>
269
+ <span class="ruby-identifier">description</span> <span class="ruby-string">&#39;Generate blog posts in given Jekyll directory from input statistics&#39;</span>
270
+ <span class="ruby-identifier">stdin</span> <span class="ruby-value">:log_data</span>, <span class="ruby-value">:cast</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-constant">YAML</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;statistic data in YAML format&#39;</span>
271
+ <span class="ruby-identifier">option</span> <span class="ruby-value">:location</span>, <span class="ruby-value">:short</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">:l</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;location name (ex. Dublin, Singapore, California)&#39;</span>
272
+ <span class="ruby-identifier">option</span> <span class="ruby-value">:csv_dir</span>, <span class="ruby-value">:short</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">:c</span>, <span class="ruby-value">:cast</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-constant">Pathname</span>, <span class="ruby-value">:default</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;csv&#39;</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;directory name where CSV file will be stored (relative to jekyll-dir)&#39;</span>
273
+ <span class="ruby-identifier">argument</span> <span class="ruby-value">:jekyll_dir</span>, <span class="ruby-value">:cast</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-constant">Pathname</span>, <span class="ruby-value">:default</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;/var/lib/vhs/jekyll&#39;</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;directory where site source is located&#39;</span>
274
+ <span class="ruby-keyword">end</span>.<span class="ruby-identifier">parse!</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">settings</span><span class="ruby-operator">|</span>
275
+ <span class="ruby-identifier">fail</span> <span class="ruby-string">&#39;jekyll-dir is not a directory&#39;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">settings</span>.<span class="ruby-identifier">jekyll_dir</span>.<span class="ruby-identifier">directory?</span>
276
+ <span class="ruby-identifier">fail</span> <span class="ruby-string">&#39;--csv-dir is not a directory (relative to jekyll-dir)&#39;</span> <span class="ruby-keyword">unless</span> (<span class="ruby-identifier">settings</span>.<span class="ruby-identifier">jekyll_dir</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">settings</span>.<span class="ruby-identifier">csv_dir</span>).<span class="ruby-identifier">directory?</span>
277
+ <span class="ruby-keyword">end</span>
278
+
279
+ <span class="ruby-identifier">p</span> <span class="ruby-identifier">settings</span>
280
+
281
+ <span class="ruby-comment"># do your stuff</span>
282
+ </pre>
283
+
284
+ <p>Example help message:</p>
285
+
286
+ <pre>Usage: processor [switches|options] [--] [jekyll-dir] &lt; log-data
287
+ Generate blog posts in given Jekyll directory from input statistics
288
+ Input:
289
+ log-data - statistic data in YAML format
290
+ Switches:
291
+ --help (-h) - display this help message
292
+ Options:
293
+ --location (-l) - location name (ex. Dublin, Singapore, California)
294
+ --csv-dir (-c) [csv] - directory name where CSV file will be stored (relative to jekyll-dir)
295
+ Arguments:
296
+ jekyll-dir [/var/lib/vhs/jekyll] - directory where site source is located</pre>
297
+
298
+ <p>With this example usage (assuming /var/lib/vhs/jekyll/csv dir exist):</p>
299
+
300
+ <pre>examples/processor --location Singapore &lt;&lt;EOF
301
+ :parser:
302
+ :successes: 41
303
+ :failures: 0
304
+ EOF</pre>
305
+
306
+ <p>The <code>settings</code> variable will contain:</p>
307
+
308
+ <pre class="ruby"><span class="ruby-comment">#&lt;CLI::Values stdin={:parser=&gt;{:successes=&gt;41, :failures=&gt;0}}, jekyll_dir=#&lt;Pathname:/var/lib/vhs/jekyll&gt;, csv_dir=#&lt;Pathname:csv&gt;, help=nil, location=&quot;Singapore&quot;&gt;</span>
309
+ </pre>
310
+
311
+ <p>Output if jekyll-dir does not exist:</p>
312
+
313
+ <pre>Error: jekyll-dir is not a directory
314
+ Usage: processor [switches|options] [--] [jekyll-dir] &lt; log-data
315
+ Generate blog posts in given Jekyll directory from input statistics
316
+ Input:
317
+ log-data - statistic data in YAML format
318
+ Switches:
319
+ --help (-h) - display this help message
320
+ Options:
321
+ --location (-l) - location name (ex. Dublin, Singapore, Califorina)
322
+ --csv-dir (-c) [csv] - directory name where CSV file will be storred (relative to jekyll-dir)
323
+ Arguments:
324
+ jekyll-dir [/var/lib/vhs/jekyll] - directory where site source is located</pre>
325
+
326
+ <h3 id="label-Ls+like+utility">Ls like utility<span><a href="#label-Ls+like+utility">&para;</a> <a href="#top">&uarr;</a></span></h3>
327
+
328
+ <p><code>arguments</code> specifier can be used to match multiple arguments. The <code>arguments</code> specifier matched value will always be an array of casted elements. Default and mandatory arguments will have priority on matching values (see specs for examples).</p>
329
+
330
+ <p><code>options</code> specifier can be used to allow specifing same option multiple times. The <code>options</code> specifier matched value will always be an array of casted elements or empty if option not specified.</p>
331
+
332
+ <pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;rubygems&#39;</span>
333
+ <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;cli&#39;</span>
334
+ <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;pathname&#39;</span>
335
+
336
+ <span class="ruby-identifier">settings</span> = <span class="ruby-constant">CLI</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">do</span>
337
+ <span class="ruby-identifier">description</span> <span class="ruby-string">&#39;Lists content of directories&#39;</span>
338
+ <span class="ruby-identifier">switch</span> <span class="ruby-value">:long</span>, <span class="ruby-value">:short</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">:l</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;use long listing&#39;</span>
339
+ <span class="ruby-identifier">options</span> <span class="ruby-value">:exclude</span>, <span class="ruby-value">:short</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">:e</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;exclude files from listing&#39;</span>
340
+ <span class="ruby-identifier">arguments</span> <span class="ruby-value">:directories</span>, <span class="ruby-value">:cast</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-constant">Pathname</span>, <span class="ruby-value">:default</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;.&#39;</span>, <span class="ruby-value">:description</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;directories to list content of&#39;</span>
341
+ <span class="ruby-keyword">end</span>.<span class="ruby-identifier">parse!</span>
342
+
343
+ <span class="ruby-identifier">settings</span>.<span class="ruby-identifier">directories</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">dir</span><span class="ruby-operator">|</span>
344
+ <span class="ruby-keyword">next</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">dir</span>.<span class="ruby-identifier">directory?</span>
345
+ <span class="ruby-identifier">dir</span>.<span class="ruby-identifier">each_entry</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
346
+ <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">==</span> <span class="ruby-string">&#39;.&#39;</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">==</span> <span class="ruby-string">&#39;..&#39;</span>
347
+ <span class="ruby-identifier">e</span> = <span class="ruby-identifier">dir</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">e</span>
348
+ <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">settings</span>.<span class="ruby-identifier">exclude</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">to_s</span>
349
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">settings</span>.<span class="ruby-identifier">long</span>
350
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;#{e.stat.uid}:#{e.stat.gid} #{e}&quot;</span>
351
+ <span class="ruby-keyword">else</span>
352
+ <span class="ruby-identifier">puts</span> <span class="ruby-identifier">e</span>
353
+ <span class="ruby-keyword">end</span>
354
+ <span class="ruby-keyword">end</span>
355
+ <span class="ruby-keyword">end</span>
356
+ </pre>
357
+
358
+ <p>Example help message:</p>
359
+
360
+ <pre>Usage: ls [switches|options] [--] [directories*]
361
+ Lists content of directories
362
+ Switches:
363
+ --long (-l) - use long listing
364
+ --help (-h) - display this help message
365
+ Options:
366
+ --exclude* (-e) - exclude files from listing
367
+ Arguments:
368
+ directories* [.] - directories to list content of</pre>
369
+
370
+ <p>Example usage:</p>
371
+
372
+ <pre class="ruby"><span class="ruby-identifier">examples</span><span class="ruby-operator">/</span><span class="ruby-identifier">ls</span>
373
+ </pre>
374
+
375
+ <p>Prints:</p>
376
+
377
+ <pre>.document
378
+ .git
379
+ .gitignore
380
+ .README.md.swp
381
+ .rspec
382
+ cli.gemspec
383
+ examples
384
+ features
385
+ ...</pre>
386
+
387
+ <p>Excluding .git and .gitignore:</p>
388
+
389
+ <pre>examples/ls -e .git -e .gitignore</pre>
390
+
391
+ <p>Prints:</p>
392
+
393
+ <pre>.document
394
+ .README.md.swp
395
+ .rspec
396
+ cli.gemspec
397
+ examples
398
+ features
399
+ ...</pre>
400
+
401
+ <p>With directory list:</p>
402
+
403
+ <pre>examples/ls *</pre>
404
+
405
+ <p>Prints:</p>
406
+
407
+ <pre>examples/.ls.swp
408
+ examples/ls
409
+ examples/processor
410
+ examples/sinatra
411
+ features/cli.feature
412
+ features/step_definitions
413
+ features/support
414
+ lib/cli
415
+ lib/cli.rb
416
+ pkg/cli-0.0.1.gem
417
+ pkg/cli-0.0.2.gem
418
+ ...</pre>
419
+
420
+ <p>Long printout:</p>
421
+
422
+ <pre>examples/ls -l *</pre>
423
+
424
+ <p>Prints:</p>
425
+
426
+ <pre>501:20 examples/.ls.swp
427
+ 501:20 examples/ls
428
+ 501:20 examples/processor
429
+ 501:20 examples/sinatra
430
+ 501:20 features/cli.feature
431
+ 501:20 features/step_definitions
432
+ 501:20 features/support
433
+ 501:20 lib/cli
434
+ 501:20 lib/cli.rb
435
+ 501:20 pkg/cli-0.0.1.gem
436
+ 501:20 pkg/cli-0.0.2.gem
437
+ ...</pre>
438
+
439
+ <h2 id="label-Usage">Usage<span><a href="#label-Usage">&para;</a> <a href="#top">&uarr;</a></span></h2>
440
+
441
+ <p><code>CLI.new</code> takes a block where you specify parser behavior. The returned object is a parser that has <code>#parse</code> and <code>#parse!</code> methods.</p>
442
+
443
+ <h3 id="label-23parse+method"><code>#parse</code> method<span><a href="#label-23parse+method">&para;</a> <a href="#top">&uarr;</a></span></h3>
444
+
445
+ <p>It will take argument array (defaults to ARGV), standard input IO (defaults to STDIO) and standard error IO (defaults to STDERR).</p>
446
+
447
+ <p>The method will parse argument array and cast standard input IO according to parser specification and return OpenStruct kind of object with resulting values.</p>
448
+
449
+ <p>The returned object will have <code>help</code> attribute set if <code>--help</code> or <code>-h</code> switch was found in argument array or <code>version</code> attribute if <code>--version</code> argument was found. In other case all the attributes will be set to appropriate values depending on argument array and parser specification. In case of parsing error <code>CLI::ParsingError</code> kind of exception will be raised.</p>
450
+
451
+ <h3 id="label-23parse-21+method"><code>#parse!</code> method<span><a href="#label-23parse-21+method">&para;</a> <a href="#top">&uarr;</a></span></h3>
452
+
453
+ <p>This is higher level version of <code>#parse</code> method that will exit the program and print out usage if there was parsing error. Also it will display usage on <code>--help</code> or <code>-h</code> switch and version string on <code>--version</code> switch found in argument array.</p>
454
+
455
+ <p>In other case it will return OpenStruct object from <code>#parse</code> method.</p>
456
+
457
+ <p>Additionally this method can be called with a block that will get the OpenStruct like object before returning it. This block should contain additional value verifications and if it raises RuntimeError (via <code>fail</code> method for instance) the error message will be displayed followed by usage and the program will exit.</p>
458
+
459
+ <h3 id="label-Parser+behavior+specifiers">Parser behavior specifiers<span><a href="#label-Parser+behavior+specifiers">&para;</a> <a href="#top">&uarr;</a></span></h3>
460
+
461
+ <h4 id="label-description+-27string-27">description ‘string’<span><a href="#label-description+-27string-27">&para;</a> <a href="#top">&uarr;</a></span></h4>
462
+
463
+ <p>The <em>string</em> will be displayed in usage output as your program short description.</p>
464
+
465
+ <h4 id="label-version+-27string-27">version ‘string’<span><a href="#label-version+-27string-27">&para;</a> <a href="#top">&uarr;</a></span></h4>
466
+
467
+ <p>The <em>string</em> representing program version that will be displayed when <code>--version</code> switch is used</p>
468
+
469
+ <h4 id="label-switch+-3Aname+-5B-2C+options+hash-5D">switch :name [, options hash]<span><a href="#label-switch+-3Aname+-5B-2C+options+hash-5D">&para;</a> <a href="#top">&uarr;</a></span></h4>
470
+
471
+ <p>When switch is specified in the command argument list the object returned by <code>#parse</code> or <code>#parse!</code> will contain argument of same name set to <code>true</code>. Otherwise the argument value will be <code>nil</code>.</p>
472
+
473
+ <p><em>:name</em> should be a symbol that will map to long switch (<code>--name</code>) where underscore (<code>_</code>) will be replaced with minus (<code>-</code>). Name has to be unique.</p>
474
+
475
+ <p>Option hash can contain following pairs:</p>
476
+ <ul><li>
477
+ <p><strong>:short =&gt; :symbol</strong> - where <em>:symbol</em> is a single letter symbol that will represent short switch name (<code>-n</code>). Short name has to be unique.</p>
478
+ </li><li>
479
+ <p><strong>:description =&gt; ‘string’</strong> - switch description string that will be displayed in the usage output</p>
480
+ </li></ul>
481
+
482
+ <h4 id="label-option+-3Aname+-5B-2C+options+hash-5D">option :name [, options hash]<span><a href="#label-option+-3Aname+-5B-2C+options+hash-5D">&para;</a> <a href="#top">&uarr;</a></span></h4>
483
+
484
+ <p>Same as <em>switch</em> but additionally it has to be followed by a value on the command argument list. The value after casting (if used) will be available from the <code>#parse</code> or <code>#parse!</code> returned object as argument of the same name.</p>
485
+
486
+ <p>In addition to <em>switch</em>, option hash can have following pairs:</p>
487
+ <ul><li>
488
+ <p><strong>:default =&gt; value</strong> - use default value of <em>value</em> if the option was not specified on the command argument list. The <em>value</em> will firstly be casted to string (with <code>#to_s</code>) and then it will be casted if casting is specified.</p>
489
+ </li><li>
490
+ <p><strong>:default_label =&gt; label</strong> - display <em>label</em> in usage rather than default value - useful to describe default value if default value is generated if no value is provided</p>
491
+ </li><li>
492
+ <p><strong>:cast =&gt; cast specifier</strong> - cast the provided value (or default) with given <em>cast specifier</em>. The specifier can be a class constant - the value will be provided to <code>#new</code> method of the class and resulting object used as option value. When provided constant does not respond to <code>#new</code> (i.e. it is a module) the <code>#load</code> method will be tried instead. If provided specifier is a Proc (or <code>lambda {}</code>) the Proc will be called with the value and resulting value will be used. Otherwise <code>CLI::ParsingError::CastError</code> will be raised. Special cast specified <code>Integer</code> or <code>Float</code> can also be used - the value will be strictly casted to integer or float type.</p>
493
+ </li><li>
494
+ <p><strong>:required =&gt; true</strong> - if used and no <em>default</em> value is specified the <code>#parse</code> method will fail with <code>CLI::ParsingError::MissingOptionValueError</code> if the option was not specified in the command argument list. If <code>#parse!</code> method was used the program will exit with appropriate message.</p>
495
+ </li></ul>
496
+
497
+ <h4 id="label-options+-3Aname+-5B-2C+options+hash-5D">options :name [, options hash]<span><a href="#label-options+-3Aname+-5B-2C+options+hash-5D">&para;</a> <a href="#top">&uarr;</a></span></h4>
498
+
499
+ <p>Same as <em>option</em> but can be specified multiple times in the command argument list. The resulting <code>#parse</code> or <code>#parse!</code> returned object will contain an argument with the same name that will always be an array. The array may be empty if the option was not used and <em>required</em> option was not set, otherwise it will contain casted values in order of specification in the command argument list.</p>
500
+
501
+ <h4 id="label-argument+-3Aname+-5B-2Coptions+hash-5D">argument :name [,options hash]<span><a href="#label-argument+-3Aname+-5B-2Coptions+hash-5D">&para;</a> <a href="#top">&uarr;</a></span></h4>
502
+
503
+ <p>After the parser encounters command line argument that is not a <em>switch</em> or <em>option</em> or it is literally <code>--</code> string it will start matching arguments.</p>
504
+
505
+ <p>Each argument will be matched to argument specifications in order and their value after optional casting will be available as <code>#parse</code> or <code>#parse!</code> returned object argument with the same name.</p>
506
+
507
+ <p>Options hash can contain the same pairs as <em>option</em> expect of <strong>:short =&gt; :symbol</strong>.</p>
508
+
509
+ <p>If defaults are used the parser will keep using default values until it has enough command line arguments available to fill all mandatory arguments. Arguments are required by default, use <strong>:required =&gt; false</strong> option pair to use <code>nil</code> value if argument is not specified on the command line argument list.</p>
510
+
511
+ <h4 id="label-arguments+-3Aname+-5B-2Coptions+hash-5D">arguments :name [,options hash]<span><a href="#label-arguments+-3Aname+-5B-2Coptions+hash-5D">&para;</a> <a href="#top">&uarr;</a></span></h4>
512
+
513
+ <p>Same as <em>argument</em> but will match one or more arguments and provide them in array of casted values. If argument is not required and not specified in command argument list then its value will be an empty array.</p>
514
+
515
+ <p>When used with <em>argument</em> specifiers that use default values the parser will try to assign at least one value to this specifier, but not more values so that all mandatory (that have no default and are required) arguments will be assigned.</p>
516
+
517
+ <h4 id="label-stdin+-3Aname-2C+-5Boptions+hash-5D">stdin :name, [options hash]<span><a href="#label-stdin+-3Aname-2C+-5Boptions+hash-5D">&para;</a> <a href="#top">&uarr;</a></span></h4>
518
+
519
+ <p>Used once to specify that stdin should be handled. When used the <code>#parse</code> or <code>#parse!</code> returned object will have <code>stdin</code> argument that by default will contain stdin IO object.</p>
520
+
521
+ <p>As with <em>switch</em> specifier the <strong>:description =&gt; ‘string’</strong> can be used. Also <strong>:cast =&gt; cast specifier</strong> option pair can be used but the value will be an IO object and not string.</p>
522
+
523
+ <h2 id="label-Contributing+to+CLI">Contributing to <a href="CLI.html"><code>CLI</code></a><span><a href="#label-Contributing+to+CLI">&para;</a> <a href="#top">&uarr;</a></span></h2>
524
+ <ul><li>
525
+ <p>Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet</p>
526
+ </li><li>
527
+ <p>Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it</p>
528
+ </li><li>
529
+ <p>Fork the project</p>
530
+ </li><li>
531
+ <p>Start a feature/bugfix branch</p>
532
+ </li><li>
533
+ <p>Commit and push until you are happy with your contribution</p>
534
+ </li><li>
535
+ <p>Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.</p>
536
+ </li><li>
537
+ <p>Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.</p>
538
+ </li></ul>
539
+
540
+ <h2 id="label-Copyright">Copyright<span><a href="#label-Copyright">&para;</a> <a href="#top">&uarr;</a></span></h2>
541
+
542
+ <p>Copyright © 2011 Jakub Pastuszek. See LICENSE.txt for further details.</p>
543
+
544
+ </main>
545
+
546
+
547
+
548
+ <footer id="validator-badges" role="contentinfo">
549
+ <p><a href="https://validator.w3.org/check/referer">Validate</a>
550
+ <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.
551
+ <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
552
+ </footer>
553
+
data/rdoc/created.rid ADDED
@@ -0,0 +1,7 @@
1
+ Thu, 24 Feb 2022 15:28:14 +0000
2
+ README.md Thu, 24 Feb 2022 14:20:37 +0000
3
+ lib/cli.rb Thu, 24 Feb 2022 14:20:37 +0000
4
+ lib/cli/arguments.rb Thu, 24 Feb 2022 14:20:37 +0000
5
+ lib/cli/dsl.rb Thu, 24 Feb 2022 14:20:37 +0000
6
+ lib/cli/options.rb Thu, 24 Feb 2022 14:20:37 +0000
7
+ lib/cli/switches.rb Thu, 24 Feb 2022 14:20:37 +0000