cliutils 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.yardoc/checksums +11 -11
  4. data/.yardoc/object_types +0 -0
  5. data/.yardoc/objects/root.dat +0 -0
  6. data/Gemfile.lock +12 -33
  7. data/README.md +1 -1
  8. data/Rakefile +36 -31
  9. data/cliutils.gemspec +3 -2
  10. data/lib/cliutils/configuration.rb +13 -31
  11. data/lib/cliutils/configurator.rb +23 -62
  12. data/lib/cliutils/ext/Hash+Extensions.rb +39 -78
  13. data/lib/cliutils/ext/Logger+Extensions.rb +6 -11
  14. data/lib/cliutils/ext/String+Extensions.rb +25 -13
  15. data/lib/cliutils/logger-delegator.rb +15 -39
  16. data/lib/cliutils/messenging.rb +10 -28
  17. data/lib/cliutils/prefs.rb +18 -43
  18. data/lib/cliutils/pretty-io.rb +59 -127
  19. data/lib/cliutils/version.rb +2 -1
  20. data/lib/cliutils.rb +2 -0
  21. metadata +20 -32
  22. data/bin/cliutils +0 -38
  23. data/doc/CLIUtils/Configuration.html +0 -373
  24. data/doc/CLIUtils/Configurator.html +0 -873
  25. data/doc/CLIUtils/LoggerDelegator.html +0 -560
  26. data/doc/CLIUtils/Messenging.html +0 -396
  27. data/doc/CLIUtils/Prefs.html +0 -609
  28. data/doc/CLIUtils/PrettyIO.html +0 -1333
  29. data/doc/CLIUtils.html +0 -131
  30. data/doc/Hash.html +0 -672
  31. data/doc/Logger.html +0 -233
  32. data/doc/String.html +0 -562
  33. data/doc/_index.html +0 -207
  34. data/doc/class_list.html +0 -54
  35. data/doc/css/common.css +0 -1
  36. data/doc/css/full_list.css +0 -57
  37. data/doc/css/style.css +0 -339
  38. data/doc/file.README.html +0 -415
  39. data/doc/file_list.html +0 -56
  40. data/doc/frames.html +0 -26
  41. data/doc/index.html +0 -415
  42. data/doc/js/app.js +0 -219
  43. data/doc/js/full_list.js +0 -178
  44. data/doc/js/jquery.js +0 -4
  45. data/doc/method_list.html +0 -389
  46. data/doc/top-level-namespace.html +0 -114
data/doc/file.README.html DELETED
@@ -1,415 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
- <head>
5
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
- <title>
7
- File: README
8
-
9
- &mdash; Documentation by YARD 0.8.7.4
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
-
15
- <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
-
17
- <script type="text/javascript" charset="utf-8">
18
- hasFrames = window.top.frames.main ? true : false;
19
- relpath = '';
20
- framesUrl = "frames.html#!file.README.html";
21
- </script>
22
-
23
-
24
- <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
25
-
26
- <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
27
-
28
-
29
- </head>
30
- <body>
31
- <div id="header">
32
- <div id="menu">
33
-
34
- <a href="_index.html">Index</a> &raquo;
35
- <span class="title">File: README</span>
36
-
37
-
38
- <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
39
- </div>
40
-
41
- <div id="search">
42
-
43
- <a class="full_list_link" id="class_list_link"
44
- href="class_list.html">
45
- Class List
46
- </a>
47
-
48
- <a class="full_list_link" id="method_list_link"
49
- href="method_list.html">
50
- Method List
51
- </a>
52
-
53
- <a class="full_list_link" id="file_list_link"
54
- href="file_list.html">
55
- File List
56
- </a>
57
-
58
- </div>
59
- <div class="clear"></div>
60
- </div>
61
-
62
- <iframe id="search_frame"></iframe>
63
-
64
- <div id="content"><div id='filecontents'>
65
- <h1 id="label-CLIUtils">CLIUtils</h1>
66
-
67
- <p>CLIUtils is a library of functionality designed to alleviate common tasks
68
- and headaches when developing command-line (CLI) apps in Ruby.</p>
69
-
70
- <h1 id="label-Why%3F">Why?</h1>
71
-
72
- <p>It&#39;s fairly simple:</p>
73
- <ol><li>
74
- <p>I love developing Ruby-based CLI apps.</p>
75
- </li><li>
76
- <p>I found myself copy/pasting common code from one to another.</p>
77
- </li><li>
78
- <p>I decided to do something about it.</p>
79
- </li></ol>
80
-
81
- <h1 id="label-Installation">Installation</h1>
82
-
83
- <p>Add this line to your application&#39;s Gemfile:</p>
84
-
85
- <pre class="code ruby"><code class="ruby">$ gem &#39;cliutils&#39;</code></pre>
86
-
87
- <p>And then execute:</p>
88
-
89
- <pre class="code ruby"><code class="ruby">$ bundle</code></pre>
90
-
91
- <p>Or install it yourself:</p>
92
-
93
- <pre class="code ruby"><code class="ruby">$ gem install cliutils</code></pre>
94
-
95
- <h1 id="label-Usage">Usage</h1>
96
-
97
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>cliutils</span><span class='tstring_end'>&#39;</span></span>
98
- </code></pre>
99
-
100
- <p>If you want to mix in everything that CLIUtils has to offer:</p>
101
-
102
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_include'>include</span> <span class='const'>CLIUtils</span></code></pre>
103
-
104
- <p>Alternatively, as described below, mix in only the libraries that you want.</p>
105
-
106
- <p>Note that although this README.md is extensive, it may not cover all
107
- methods. Check out the <a
108
- href="https://github.com/bachya/cli-utils/tree/master/test">tests</a> to
109
- see more examples.</p>
110
-
111
- <h1 id="label-Libraries">Libraries</h1>
112
-
113
- <p>CLIUtils offers:</p>
114
- <ul><li>
115
- <p><a href="https://github.com/bachya/cli-utils#prettyio">PrettyIO</a>:
116
- nicer-looking CLI messages</p>
117
- </li><li>
118
- <p><a href="https://github.com/bachya/cli-utils#messenging">Messenging</a>: a
119
- full-featured Logger</p>
120
- </li><li>
121
- <p><a
122
- href="https://github.com/bachya/cli-utils#configuration">Configuration</a>:
123
- a app configuration manager</p>
124
- </li><li>
125
- <p><a href="https://github.com/bachya/cli-utils#prefs">Prefs</a>: a
126
- preferences prompter and manager</p>
127
- </li></ul>
128
-
129
- <h2 id="label-PrettyIO">PrettyIO</h2>
130
-
131
- <p>First stop on our journey is better client IO. To activate, simply mix into
132
- your project:</p>
133
-
134
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_include'>include</span> <span class='const'>CLIUtils</span><span class='op'>::</span><span class='const'>PrettyIO</span>
135
- </code></pre>
136
-
137
- <p>PrettyIO affords you colorized strings:</p>
138
-
139
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>A sample string</span><span class='tstring_end'>&#39;</span></span><span class='period'>.</span><span class='id identifier rubyid_red'>red</span>
140
- </code></pre>
141
-
142
- <p><img
143
- src="https://raw.githubusercontent.com/bachya/cli-utils/master/res/readme-images/prettyio-red-text.png"></p>
144
-
145
- <p>PrettyIO gives you utility methods for the common ANSI color codes:</p>
146
-
147
- <pre class="code ruby"><code class="ruby"><span class='const'>String</span><span class='period'>.</span><span class='id identifier rubyid_blue'>blue</span>
148
- <span class='const'>String</span><span class='period'>.</span><span class='id identifier rubyid_cyan'>cyan</span>
149
- <span class='const'>String</span><span class='period'>.</span><span class='id identifier rubyid_green'>green</span>
150
- <span class='const'>String</span><span class='period'>.</span><span class='id identifier rubyid_purple'>purple</span>
151
- <span class='const'>String</span><span class='period'>.</span><span class='id identifier rubyid_red'>red</span>
152
- <span class='const'>String</span><span class='period'>.</span><span class='id identifier rubyid_white'>white</span>
153
- <span class='const'>String</span><span class='period'>.</span><span class='id identifier rubyid_yellow'>yellow</span>
154
- </code></pre>
155
-
156
- <p>You also get the <code>colorize</code> method, which allows you to define
157
- more complex color combinations. For example, to get some nice purple text
158
- on a gnarly green background:</p>
159
-
160
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>A sample string</span><span class='tstring_end'>&#39;</span></span><span class='period'>.</span><span class='id identifier rubyid_colorize'>colorize</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>35;42</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
161
- </code></pre>
162
-
163
- <p><img
164
- src="https://raw.githubusercontent.com/bachya/cli-utils/master/res/readme-images/prettyio-gnarly-text.png"></p>
165
-
166
- <p>Naturally, memorizing the ANSI color scheme is a pain, so PrettyIO gives
167
- you a convenient method to look up these color combinations:</p>
168
-
169
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_color_chart'>color_chart</span>
170
- </code></pre>
171
-
172
- <p><img
173
- src="https://raw.githubusercontent.com/bachya/cli-utils/master/res/readme-images/prettyio-color-chart.png"></p>
174
-
175
- <h2 id="label-Messenging">Messenging</h2>
176
-
177
- <p>Throughout the life of your application, you will most likely want to send
178
- several messages to your user (warnings, errors, info, etc.). Messenging
179
- makes this a snap. It, too, is a mixin:</p>
180
-
181
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_include'>include</span> <span class='const'>CLIUtils</span><span class='op'>::</span><span class='const'>Messenging</span>
182
- </code></pre>
183
-
184
- <p>Once mixed in, you get access to <code>messenger</code>, a type of Logger
185
- that uses PrettyIO to send nicely-formatted messages to your user. For
186
- example, if you&#39;d like to warn your user:</p>
187
-
188
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_warn'>warn</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Hey pal, you need to be careful.</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
189
- </code></pre>
190
-
191
- <p><img
192
- src="https://raw.githubusercontent.com/bachya/cli-utils/master/res/readme-images/messenger-warn.png"></p>
193
-
194
- <h3 id="label-Messenging+Methods">Messenging Methods</h3>
195
-
196
- <p><code>messenger</code> gives you access to several basic methods:</p>
197
- <ul><li>
198
- <p><code>messenger.error</code>: used to show a formatted-red error message.</p>
199
- </li><li>
200
- <p><code>messenger.info</code>: used to show a formatted-blue infomational
201
- message.</p>
202
- </li><li>
203
- <p><code>messenger.section</code>: used to show a formatted-purple sectional
204
- message.</p>
205
- </li><li>
206
- <p><code>messenger.success</code>: used to show a formatted-green success
207
- message.</p>
208
- </li><li>
209
- <p><code>messenger.yellow</code>: used to show a formatted-yellow warning
210
- message.</p>
211
- </li></ul>
212
-
213
- <p>Let&#39;s see an example that uses them all:</p>
214
-
215
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_section'>section</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>STARTING ATTACK RUN...</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
216
- <span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_info'>info</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Beginning strafing run...</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
217
- <span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_warn'>warn</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>WARNING: Tie Fighters approaching!</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
218
- <span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_error'>error</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Porkins died :(</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
219
- <span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_success'>success</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>But Luke still blew up the Death Star!</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span></code></pre>
220
-
221
- <p><img
222
- src="https://raw.githubusercontent.com/bachya/cli-utils/master/res/readme-images/messenger-types-1.png"></p>
223
-
224
- <p><code>messenger</code> also includes two “block” methods that allow you to
225
- wrap program execution in messages that are “longer-term”.</p>
226
-
227
- <pre class="code ruby"><code class="ruby">messenger.info_block(&#39;Starting up...&#39;, &#39;Done!&#39;, multiline = false) { # do stuff here }</code></pre>
228
-
229
- <p><code>messenger</code> outputs &#39;Starting up…&#39;, runs the code in
230
- <code># do stuff here</code>, and once complete, outputs &#39;Done!&#39; on
231
- the same line. Note that <code>section_block</code> is the same exact
232
- signature (except for the method name, of course!).</p>
233
-
234
- <h3 id="label-Message+Wrapping">Message Wrapping</h3>
235
-
236
- <p>PrettyIO also gives <code>messenger</code> the ability to wrap your
237
- messages so that they don&#39;t span off into infinity. You can even
238
- control what the wrap limit (in characters) is:</p>
239
-
240
- <pre class="code ruby"><code class="ruby"><span class='const'>CLIUtils</span><span class='op'>::</span><span class='const'>PrettyIO</span><span class='op'>::</span><span class='id identifier rubyid_wrap_at'>wrap_at</span><span class='lparen'>(</span><span class='int'>50</span><span class='rparen'>)</span>
241
- <span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_info'>info</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>This is a really long message, okay? It should wrap at some point. Seriously. Wrapping is nice.</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
242
- <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_end'>&#39;</span></span>
243
- <span class='const'>CLIUtils</span><span class='op'>::</span><span class='const'>PrettyIO</span><span class='op'>::</span><span class='id identifier rubyid_wrap_at'>wrap_at</span><span class='lparen'>(</span><span class='int'>20</span><span class='rparen'>)</span>
244
- <span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_info'>info</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>This is a really long message, okay? It should wrap at some point. Seriously. Wrapping is nice.</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
245
- <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_end'>&#39;</span></span>
246
- <span class='const'>CLIUtils</span><span class='op'>::</span><span class='const'>PrettyIO</span><span class='op'>::</span><span class='id identifier rubyid_wrap'>wrap</span><span class='lparen'>(</span><span class='kw'>false</span><span class='rparen'>)</span>
247
- <span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_info'>info</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>This is a really long message, okay? It should wrap at some point. Seriously. Wrapping is nice.</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span></code></pre>
248
-
249
- <p><img
250
- src="https://raw.githubusercontent.com/bachya/cli-utils/master/res/readme-images/wrapping.png"></p>
251
-
252
- <h3 id="label-Prompting">Prompting</h3>
253
-
254
- <p><code>messenger</code> also carries a convenient method to prompt your
255
- users to give input (including an optional default). It makes use of
256
- <code>readline</code>, so you can do cool things like text expansion of
257
- paths.</p>
258
-
259
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_p'>p</span> <span class='op'>=</span> <span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_prompt'>prompt</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Are you a fan of Battlestar Galactica?</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='id identifier rubyid_default'>default</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Y</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
260
- <span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_info'>info</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>You answered: </span><span class='embexpr_beg'>#{</span> <span class='id identifier rubyid_p'>p</span> <span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span></code></pre>
261
-
262
- <p><img
263
- src="https://raw.githubusercontent.com/bachya/cli-utils/master/res/readme-images/prompting.png"></p>
264
-
265
- <h3 id="label-Logging">Logging</h3>
266
-
267
- <p>Often, it&#39;s desirable to log messages as they appear to your user.
268
- <code>messenging</code> makes this a breeze by allowing you to attach and
269
- detach Logger instances at will.</p>
270
-
271
- <p>For instance, let&#39;s say you wanted to log a few messages to both your
272
- user&#39;s STDOUT and to <code>file.txt</code>:</p>
273
-
274
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_file_logger'>file_logger</span> <span class='op'>=</span> <span class='const'>Logger</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>file.txt</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
275
-
276
- <span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_info'>info</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>This should only appear in STDOUT.</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
277
-
278
- <span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_attach'>attach</span><span class='lparen'>(</span><span class='id identifier rubyid_file_logger'>file_logger</span><span class='rparen'>)</span>
279
-
280
- <span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_warn'>warn</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>This warning should appear in STDOUT and file.txt</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
281
- <span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_error'>error</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>This error should appear in STDOUT and file.txt</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
282
- <span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>This debug message should only appear in file.txt</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
283
-
284
- <span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_detach'>detach</span><span class='lparen'>(</span><span class='id identifier rubyid_file_logger'>file_logger</span><span class='rparen'>)</span>
285
-
286
- <span class='id identifier rubyid_messenger'>messenger</span><span class='period'>.</span><span class='id identifier rubyid_section'>section</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>This section message should appear only in STDOUT</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span></code></pre>
287
-
288
- <p>In STDOUT:</p>
289
-
290
- <p><img
291
- src="https://raw.githubusercontent.com/bachya/cli-utils/master/res/readme-images/multi-logger.png"></p>
292
-
293
- <p>…and in <code>file.txt</code>:</p>
294
-
295
- <pre class="code ruby"><code class="ruby">W, [2014-03-29T15:14:34.844406 #4497] WARN -- : This warning should appear in STDOUT and file.txt
296
- E, [2014-03-29T15:14:34.844553 #4497] ERROR -- : This error should appear in STDOUT and file.txt
297
- D, [2014-03-29T15:14:34.844609 #4497] DEBUG -- : This debug message should only appear in file.txt</code></pre>
298
-
299
- <p>Since you can attach Logger objects, each can have it&#39;s own format and
300
- severity level. Cool!</p>
301
-
302
- <h2 id="label-Configuration">Configuration</h2>
303
-
304
- <p>CLIUtils offers two “things” – a <code>Configurator</code> class and a
305
- <code>Configuration</code> module that provides access to a shared instance
306
- of <code>Configurator</code> – that make managing a user&#39;s
307
- configuration parameters easy. Mix it in!</p>
308
-
309
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_include'>include</span> <span class='const'>CLIUtils</span><span class='op'>::</span><span class='const'>Configuration</span></code></pre>
310
-
311
- <h3 id="label-Loading+a+Configuration+File">Loading a Configuration File</h3>
312
-
313
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_load_configuration'>load_configuration</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>~/.my-app-config</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span></code></pre>
314
-
315
- <p>If there&#39;s data in there, it will be consumed into
316
- <code>configuration</code>&#39;s <code>data</code> property.</p>
317
-
318
- <h3 id="label-Adding%2FRemoving+Sections">Adding/Removing Sections</h3>
319
-
320
- <p>Sections are top levels of the configuration file and are managed via the
321
- <code>configuration</code> object:</p>
322
-
323
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_configuration'>configuration</span><span class='period'>.</span><span class='id identifier rubyid_add_section'>add_section</span><span class='lparen'>(</span><span class='symbol'>:user_data</span><span class='rparen'>)</span>
324
- <span class='id identifier rubyid_configuration'>configuration</span><span class='period'>.</span><span class='id identifier rubyid_add_section'>add_section</span><span class='lparen'>(</span><span class='symbol'>:program_data</span><span class='rparen'>)</span>
325
- <span class='id identifier rubyid_configuration'>configuration</span><span class='period'>.</span><span class='id identifier rubyid_delete_section'>delete_section</span><span class='lparen'>(</span><span class='symbol'>:program_data</span><span class='rparen'>)</span></code></pre>
326
-
327
- <h3 id="label-Adding+Data+to+Sections">Adding Data to Sections</h3>
328
-
329
- <p>There are two ways data can be managed in <code>configuration</code>: via
330
- its <code>@data</code> property or via some magic methods; your call:</p>
331
-
332
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_configuration'>configuration</span><span class='period'>.</span><span class='id identifier rubyid_data'>data</span><span class='lbracket'>[</span><span class='symbol'>:user_data</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_merge!'>merge!</span><span class='lparen'>(</span><span class='label'>username:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>bob</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
333
- <span class='comment'># OR
334
- </span><span class='id identifier rubyid_configuration'>configuration</span><span class='period'>.</span><span class='id identifier rubyid_user_data'>user_data</span><span class='period'>.</span><span class='id identifier rubyid_merge!'>merge!</span><span class='lparen'>(</span><span class='label'>username:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>bob</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span></code></pre>
335
-
336
- <h3 id="label-Saving+to+a+File">Saving to a File</h3>
337
-
338
- <p>When you&#39;re ready to save your configuration data to a YAML file:</p>
339
-
340
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_configuration'>configuration</span><span class='period'>.</span><span class='id identifier rubyid_save'>save</span></code></pre>
341
-
342
- <p>Note that all your keys are converted to strings before saving (and,
343
- likewise, are converted to symbols, when loading). Assuming we used the
344
- commands above, we could expect this to be the contents of
345
- <code>~/.my-app-config</code>:</p>
346
-
347
- <pre class="code ruby"><code class="ruby">---
348
- user_data:
349
- username: bob</code></pre>
350
-
351
- <h1 id="label-Known+Issues">Known Issues</h1>
352
- <ul><li>
353
- <p>LoggerDelegator doesn&#39;t currently know what to do with
354
- <code>messenger.prompt</code>, so you&#39;ll have to manually log a
355
- <code>debug</code> message if you want that information logged.</p>
356
- </li></ul>
357
-
358
- <h1 id="label-Bugs+and+Feature+Requests">Bugs and Feature Requests</h1>
359
-
360
- <p>To report bugs with or suggest features/changes for CLIUtils, please use
361
- the <a href="http://github.com/bachya/cli-utils/issues">Issues Page</a>.</p>
362
-
363
- <h1 id="label-Contributing">Contributing</h1>
364
-
365
- <p>Contributions are welcome and encouraged. To contribute:</p>
366
- <ol><li>
367
- <p>Fork it ( <a
368
- href="http://github.com/bachya/cliutils/fork">github.com/bachya/cliutils/fork</a>
369
- )</p>
370
- </li><li>
371
- <p>Create your feature branch (<code>git checkout -b my-new-feature</code>)</p>
372
- </li><li>
373
- <p>Commit your changes (<code>git commit -am &#39;Add some
374
- feature&#39;</code>)</p>
375
- </li><li>
376
- <p>Push to the branch (<code>git push origin my-new-feature</code>)</p>
377
- </li><li>
378
- <p>Create new Pull Request</p>
379
- </li></ol>
380
-
381
- <h1 id="label-License">License</h1>
382
-
383
- <p>(The MIT License)</p>
384
-
385
- <p>Copyright © 2014 Aaron Bach <a
386
- href="mailto:bachya1208@gmail.com">bachya1208@gmail.com</a></p>
387
-
388
- <p>Permission is hereby granted, free of charge, to any person obtaining a
389
- copy of this software and associated documentation files (the
390
- &#39;Software&#39;), to deal in the Software without restriction, including
391
- without limitation the rights to use, copy, modify, merge, publish,
392
- distribute, sublicense, and/or sell copies of the Software, and to permit
393
- persons to whom the Software is furnished to do so, subject to the
394
- following conditions:</p>
395
-
396
- <p>The above copyright notice and this permission notice shall be included in
397
- all copies or substantial portions of the Software.</p>
398
-
399
- <p>THE SOFTWARE IS PROVIDED &#39;AS IS&#39;, WITHOUT WARRANTY OF ANY KIND,
400
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
401
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
402
- NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
403
- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
404
- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
405
- USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
406
- </div></div>
407
-
408
- <div id="footer">
409
- Generated on Sat Mar 29 17:22:03 2014 by
410
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
411
- 0.8.7.4 (ruby-2.1.0).
412
- </div>
413
-
414
- </body>
415
- </html>
data/doc/file_list.html DELETED
@@ -1,56 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html>
4
- <head>
5
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
-
7
- <link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" charset="utf-8" />
8
-
9
- <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
10
-
11
-
12
-
13
- <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
14
-
15
- <script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
16
-
17
-
18
- <title>File List</title>
19
- <base id="base_target" target="_parent" />
20
- </head>
21
- <body>
22
- <script type="text/javascript" charset="utf-8">
23
- if (window.top.frames.main) {
24
- document.getElementById('base_target').target = 'main';
25
- document.body.className = 'frames';
26
- }
27
- </script>
28
- <div id="content">
29
- <h1 id="full_list_header">File List</h1>
30
- <div id="nav">
31
-
32
- <span><a target="_self" href="class_list.html">
33
- Classes
34
- </a></span>
35
-
36
- <span><a target="_self" href="method_list.html">
37
- Methods
38
- </a></span>
39
-
40
- <span><a target="_self" href="file_list.html">
41
- Files
42
- </a></span>
43
-
44
- </div>
45
- <div id="search">Search: <input type="text" /></div>
46
-
47
- <ul id="full_list" class="file">
48
-
49
-
50
- <li class="r1"><span class="object_link"><a href="index.html" title="README">README</a></a></li>
51
-
52
-
53
- </ul>
54
- </div>
55
- </body>
56
- </html>
data/doc/frames.html DELETED
@@ -1,26 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
3
-
4
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
- <head>
6
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
7
- <title>Documentation by YARD 0.8.7.4</title>
8
- </head>
9
- <script type="text/javascript" charset="utf-8">
10
- window.onload = function() {
11
- var match = unescape(window.location.hash).match(/^#!(.+)/);
12
- var name = match ? match[1] : 'index.html';
13
- name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
14
- document.writeln('<frameset cols="20%,*">' +
15
- '<frame name="list" src="class_list.html" />' +
16
- '<frame name="main" src="' + escape(name) + '" />' +
17
- '</frameset>');
18
- }
19
- </script>
20
- <noscript>
21
- <frameset cols="20%,*">
22
- <frame name="list" src="class_list.html" />
23
- <frame name="main" src="index.html" />
24
- </frameset>
25
- </noscript>
26
- </html>