cliutils 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.gitignore +1 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +48 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +288 -0
  8. data/README.rdoc +19 -0
  9. data/Rakefile +45 -0
  10. data/bin/cliutils +38 -0
  11. data/cliutils.gemspec +28 -0
  12. data/features/cli_manager.feature +13 -0
  13. data/features/step_definitions/cli_manager_steps.rb +1 -0
  14. data/features/support/env.rb +16 -0
  15. data/html/CLIUtils/Configuration.html +271 -0
  16. data/html/CLIUtils/Configurator.html +504 -0
  17. data/html/CLIUtils/LoggerDelegator.html +344 -0
  18. data/html/CLIUtils/Messenging.html +284 -0
  19. data/html/CLIUtils/Prefs.html +330 -0
  20. data/html/CLIUtils/PrettyIO.html +799 -0
  21. data/html/CLIUtils.html +112 -0
  22. data/html/Hash.html +453 -0
  23. data/html/Logger.html +183 -0
  24. data/html/Object.html +120 -0
  25. data/html/README_md.html +454 -0
  26. data/html/String.html +413 -0
  27. data/html/created.rid +13 -0
  28. data/html/fonts/Lato-Light.ttf +0 -0
  29. data/html/fonts/Lato-LightItalic.ttf +0 -0
  30. data/html/fonts/Lato-Regular.ttf +0 -0
  31. data/html/fonts/Lato-RegularItalic.ttf +0 -0
  32. data/html/fonts/SourceCodePro-Bold.ttf +0 -0
  33. data/html/fonts/SourceCodePro-Regular.ttf +0 -0
  34. data/html/fonts.css +167 -0
  35. data/html/images/add.png +0 -0
  36. data/html/images/arrow_up.png +0 -0
  37. data/html/images/brick.png +0 -0
  38. data/html/images/brick_link.png +0 -0
  39. data/html/images/bug.png +0 -0
  40. data/html/images/bullet_black.png +0 -0
  41. data/html/images/bullet_toggle_minus.png +0 -0
  42. data/html/images/bullet_toggle_plus.png +0 -0
  43. data/html/images/date.png +0 -0
  44. data/html/images/delete.png +0 -0
  45. data/html/images/find.png +0 -0
  46. data/html/images/loadingAnimation.gif +0 -0
  47. data/html/images/macFFBgHack.png +0 -0
  48. data/html/images/package.png +0 -0
  49. data/html/images/page_green.png +0 -0
  50. data/html/images/page_white_text.png +0 -0
  51. data/html/images/page_white_width.png +0 -0
  52. data/html/images/plugin.png +0 -0
  53. data/html/images/ruby.png +0 -0
  54. data/html/images/tag_blue.png +0 -0
  55. data/html/images/tag_green.png +0 -0
  56. data/html/images/transparent.png +0 -0
  57. data/html/images/wrench.png +0 -0
  58. data/html/images/wrench_orange.png +0 -0
  59. data/html/images/zoom.png +0 -0
  60. data/html/index.html +455 -0
  61. data/html/js/darkfish.js +140 -0
  62. data/html/js/jquery.js +18 -0
  63. data/html/js/navigation.js +142 -0
  64. data/html/js/search.js +109 -0
  65. data/html/js/search_index.js +1 -0
  66. data/html/js/searcher.js +228 -0
  67. data/html/rdoc.css +580 -0
  68. data/html/table_of_contents.html +399 -0
  69. data/lib/.DS_Store +0 -0
  70. data/lib/cliutils/configuration.rb +48 -0
  71. data/lib/cliutils/configurator.rb +119 -0
  72. data/lib/cliutils/ext/Hash+Extensions.rb +145 -0
  73. data/lib/cliutils/ext/Logger+Extensions.rb +27 -0
  74. data/lib/cliutils/ext/String+Extensions.rb +26 -0
  75. data/lib/cliutils/logger-delegator.rb +66 -0
  76. data/lib/cliutils/messenging.rb +51 -0
  77. data/lib/cliutils/prefs.rb +116 -0
  78. data/lib/cliutils/pretty-io.rb +255 -0
  79. data/lib/cliutils/version.rb +3 -0
  80. data/lib/cliutils.rb +15 -0
  81. data/res/readme-images/messenger-types-1.png +0 -0
  82. data/res/readme-images/messenger-warn.png +0 -0
  83. data/res/readme-images/multi-logger.png +0 -0
  84. data/res/readme-images/prettyio-color-chart.png +0 -0
  85. data/res/readme-images/prettyio-gnarly-text.png +0 -0
  86. data/res/readme-images/prettyio-red-text.png +0 -0
  87. data/res/readme-images/prompting.png +0 -0
  88. data/res/readme-images/wrapping.png +0 -0
  89. data/test/configurator_test.rb +50 -0
  90. data/test/hash_extensions_test.rb +50 -0
  91. data/test/logger_extensions_test.rb +16 -0
  92. data/test/messenging_test.rb +53 -0
  93. data/test/prefs_test.rb +29 -0
  94. data/test/string_extesions_test.rb +14 -0
  95. data/test/test_files/prefstest.yaml +33 -0
  96. metadata +199 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0754feae910c80be0a06a3b11353926cc8c79c28
4
+ data.tar.gz: afbe8b57e41c27f8d37479305acfe9a8834803df
5
+ SHA512:
6
+ metadata.gz: c948a61c5ee399c1b921e3fb825201dcce07ec45b4ba1923ec28cd4131acc718eedb3143395899d5c2cd1895aedac1db6eba42a4ae1c4061239983da88489f71
7
+ data.tar.gz: 1aa55f1a16bd3c6035b0a0c459d8f8158d0186e732adebba479da8cbc14e1666b1987f8b3cf517ab08eb1af44ecca06966651ba9290fb5dd68f7c0eaf78ded8f
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cliutils.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cliutils (0.0.1)
5
+ methadone (~> 1.3.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ aruba (0.5.4)
11
+ childprocess (>= 0.3.6)
12
+ cucumber (>= 1.1.1)
13
+ rspec-expectations (>= 2.7.0)
14
+ builder (3.2.2)
15
+ childprocess (0.5.1)
16
+ ffi (~> 1.0, >= 1.0.11)
17
+ cucumber (1.3.12)
18
+ builder (>= 2.1.2)
19
+ diff-lcs (>= 1.1.3)
20
+ gherkin (~> 2.12)
21
+ multi_json (>= 1.7.5, < 2.0)
22
+ multi_test (>= 0.1.1)
23
+ diff-lcs (1.2.5)
24
+ ffi (1.9.3)
25
+ gherkin (2.12.2)
26
+ multi_json (~> 1.3)
27
+ json (1.8.1)
28
+ methadone (1.3.2)
29
+ bundler
30
+ multi_json (1.9.2)
31
+ multi_test (0.1.1)
32
+ rake (0.9.2.2)
33
+ rdoc (4.1.1)
34
+ json (~> 1.4)
35
+ rspec-expectations (3.0.0.beta2)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (= 3.0.0.beta2)
38
+ rspec-support (3.0.0.beta2)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ aruba
45
+ bundler (~> 1.5)
46
+ cliutils!
47
+ rake (~> 0.9.2)
48
+ rdoc
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Aaron Bach
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,288 @@
1
+ CLIUtils
2
+ ====
3
+
4
+ CLIUtils is a library of functionality designed to alleviate common tasks and headaches when developing command-line (CLI) apps in Ruby.
5
+
6
+ # Why?
7
+
8
+ It's fairly simple:
9
+
10
+ 1. I love developing Ruby-based CLI apps.
11
+ 2. I found myself copy/pasting common code from one to another.
12
+ 3. I decided to do something about it.
13
+
14
+ # Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```bash
19
+ $ gem 'cliutils'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ ```bash
25
+ $ bundle
26
+ ```
27
+
28
+ Or install it yourself:
29
+
30
+ ```bash
31
+ $ gem install cliutils
32
+ ```
33
+
34
+ # Usage
35
+
36
+ ```ruby
37
+ require 'cliutils'
38
+ ```
39
+
40
+ If you want to mix in everything that CLIUtils has to offer:
41
+
42
+ ```Ruby
43
+ include CLIUtils
44
+ ```
45
+
46
+ Alternatively, as described below, mix in only the libraries that you want.
47
+
48
+ Note that although this README.md is extensive, it may not cover all methods. Check out the [tests](https://github.com/bachya/cli-utils/tree/master/test) to see more examples.
49
+
50
+ # Libraries
51
+
52
+ CLIUtils offers:
53
+
54
+ * [PrettyIO](https://github.com/bachya/cli-utils#prettyio): nicer-looking CLI messages
55
+ * [Messenging](https://github.com/bachya/cli-utils#messenging): a full-featured Logger
56
+ * [Configuration](https://github.com/bachya/cli-utils#configuration): a app configuration manager
57
+ * [Prefs](https://github.com/bachya/cli-utils#prefs): a preferences prompter and manager
58
+
59
+ ## PrettyIO
60
+
61
+ First stop on our journey is better client IO. To activate, simply mix into your project:
62
+
63
+ ```ruby
64
+ include CLIUtils::PrettyIO
65
+ ```
66
+
67
+ PrettyIO affords you colorized strings:
68
+
69
+ ```ruby
70
+ puts 'A sample string'.red
71
+ ```
72
+ ![alt text](https://raw.githubusercontent.com/bachya/cli-utils/master/res/readme-images/prettyio-red-text.png "Colored Text via PrettyIO")
73
+
74
+ PrettyIO gives you utility methods for the common ANSI color codes:
75
+
76
+ ```ruby
77
+ String.blue
78
+ String.cyan
79
+ String.green
80
+ String.purple
81
+ String.red
82
+ String.white
83
+ String.yellow
84
+ ```
85
+
86
+ You also get the `colorize` method, which allows you to define more complex color combinations. For example, to get some nice purple text on a gnarly green background:
87
+
88
+ ```ruby
89
+ puts 'A sample string'.colorize('35;42')
90
+ ```
91
+ ![alt text](https://raw.githubusercontent.com/bachya/cli-utils/master/res/readme-images/prettyio-gnarly-text.png "Complex Colored Text via PrettyIO")
92
+
93
+ Naturally, memorizing the ANSI color scheme is a pain, so PrettyIO gives you a convenient method to look up these color combinations:
94
+
95
+ ```ruby
96
+ color_chart
97
+ ```
98
+ ![alt text](https://raw.githubusercontent.com/bachya/cli-utils/master/res/readme-images/prettyio-color-chart.png "PrettyIO Color Chart")
99
+
100
+ ## Messenging
101
+
102
+ Throughout the life of your application, you will most likely want to send several messages to your user (warnings, errors, info, etc.). Messenging makes this a snap. It, too, is a mixin:
103
+
104
+ ```ruby
105
+ include CLIUtils::Messenging
106
+ ```
107
+
108
+ Once mixed in, you get access to `messenger`, a type of Logger that uses PrettyIO to send nicely-formatted messages to your user. For example, if you'd like to warn your user:
109
+
110
+ ```ruby
111
+ messenger.warn('Hey pal, you need to be careful.')
112
+ ```
113
+ ![alt text](https://raw.githubusercontent.com/bachya/cli-utils/master/res/readme-images/messenger-warn.png "A Warning from Messenger")
114
+
115
+ ### Messenging Methods
116
+
117
+ `messenger` gives you access to several basic methods:
118
+
119
+ * `messenger.error`: used to show a formatted-red error message.
120
+ * `messenger.info`: used to show a formatted-blue infomational message.
121
+ * `messenger.section`: used to show a formatted-purple sectional message.
122
+ * `messenger.success`: used to show a formatted-green success message.
123
+ * `messenger.yellow`: used to show a formatted-yellow warning message.
124
+
125
+ Let's see an example that uses them all:
126
+
127
+ ```Ruby
128
+ messenger.section('STARTING ATTACK RUN...')
129
+ messenger.info('Beginning strafing run...')
130
+ messenger.warn('WARNING: Tie Fighters approaching!')
131
+ messenger.error('Porkins died :(')
132
+ messenger.success('But Luke still blew up the Death Star!')
133
+ ```
134
+ ![alt text](https://raw.githubusercontent.com/bachya/cli-utils/master/res/readme-images/messenger-types-1.png "Basic Messenger Types")
135
+
136
+ `messenger` also includes two "block" methods that allow you to wrap program execution in messages that are "longer-term".
137
+
138
+ ```Ruby
139
+ messenger.info_block('Starting up...', 'Done!', multiline = false) { # do stuff here }
140
+ ```
141
+
142
+ `messenger` outputs 'Starting up...', runs the code in `# do stuff here`, and once complete, outputs 'Done!' on the same line. Note that `section_block` is the same exact signature (except for the method name, of course!).
143
+
144
+ ### Message Wrapping
145
+
146
+ PrettyIO also gives `messenger` the ability to wrap your messages so that they don't span off into infinity. You can even control what the wrap limit (in characters) is:
147
+
148
+ ```Ruby
149
+ CLIUtils::PrettyIO::wrap_at(50)
150
+ messenger.info('This is a really long message, okay? It should wrap at some point. Seriously. Wrapping is nice.')
151
+ puts ''
152
+ CLIUtils::PrettyIO::wrap_at(20)
153
+ messenger.info('This is a really long message, okay? It should wrap at some point. Seriously. Wrapping is nice.')
154
+ puts ''
155
+ CLIUtils::PrettyIO::wrap(false)
156
+ messenger.info('This is a really long message, okay? It should wrap at some point. Seriously. Wrapping is nice.')
157
+ ```
158
+ ![alt text](https://raw.githubusercontent.com/bachya/cli-utils/master/res/readme-images/wrapping.png "Text Wrapping")
159
+
160
+ ### Prompting
161
+
162
+ `messenger` also carries a convenient method to prompt your users to give input (including an optional default). It makes use of `readline`, so you can do cool things like text expansion of paths.
163
+
164
+ ```Ruby
165
+ p = messenger.prompt('Are you a fan of Battlestar Galactica?', default = 'Y')
166
+ messenger.info("You answered: #{ p }")
167
+ ```
168
+ ![alt text](https://raw.githubusercontent.com/bachya/cli-utils/master/res/readme-images/prompting.png "Prompting")
169
+
170
+ ### Logging
171
+
172
+ Often, it's desirable to log messages as they appear to your user. `messenging` makes this a breeze by allowing you to attach and detach Logger instances at will.
173
+
174
+ For instance, let's say you wanted to log a few messages to both your user's STDOUT and to `file.txt`:
175
+
176
+ ```Ruby
177
+ file_logger = Logger.new('file.txt')
178
+
179
+ messenger.info('This should only appear in STDOUT.')
180
+
181
+ messenger.attach(file_logger)
182
+
183
+ messenger.warn('This warning should appear in STDOUT and file.txt')
184
+ messenger.error('This error should appear in STDOUT and file.txt')
185
+ messenger.debug('This debug message should only appear in file.txt')
186
+
187
+ messenger.detach(file_logger)
188
+
189
+ messenger.section('This section message should appear only in STDOUT')
190
+ ```
191
+
192
+ In STDOUT:
193
+
194
+ ![alt text](https://raw.githubusercontent.com/bachya/cli-utils/master/res/readme-images/multi-logger.png "Multi-logging")
195
+
196
+ ...and in `file.txt`:
197
+
198
+ ```
199
+ W, [2014-03-29T15:14:34.844406 #4497] WARN -- : This warning should appear in STDOUT and file.txt
200
+ E, [2014-03-29T15:14:34.844553 #4497] ERROR -- : This error should appear in STDOUT and file.txt
201
+ D, [2014-03-29T15:14:34.844609 #4497] DEBUG -- : This debug message should only appear in file.txt
202
+ ```
203
+
204
+ Since you can attach Logger objects, each can have it's own format and severity level. Cool!
205
+
206
+ ## Configuration
207
+
208
+ CLIUtils offers two "things" -- a `Configurator` class and a `Configuration` module that provides access to a shared instance of `Configurator` -- that make managing a user's configuration parameters easy. Mix it in!
209
+
210
+ ```Ruby
211
+ include CLIUtils::Configuration
212
+ ```
213
+
214
+ ### Loading a Configuration File
215
+
216
+ ```Ruby
217
+ load_configuration('~/.my-app-config')
218
+ ```
219
+
220
+ If there's data in there, it will be consumed into `configuration`'s `data` property.
221
+
222
+ ### Adding/Removing Sections
223
+
224
+ Sections are top levels of the configuration file and are managed via the `configuration` object:
225
+
226
+ ```Ruby
227
+ configuration.add_section(:user_data)
228
+ configuration.add_section(:program_data)
229
+ configuration.delete_section(:program_data)
230
+ ```
231
+
232
+ ### Adding Data to Sections
233
+
234
+ There are two ways data can be managed in `configuration`: via its `@data` property or via some magic methods; your call:
235
+
236
+ ```Ruby
237
+ configuration.data[:user_data].merge!(username: 'bob')
238
+ # OR
239
+ configuration.user_data.merge!(username: 'bob')
240
+ ```
241
+
242
+ ### Saving to a File
243
+
244
+ When you're ready to save your configuration data to a YAML file:
245
+
246
+ ```Ruby
247
+ configuration.save
248
+ ```
249
+
250
+ Note that all your keys are converted to strings before saving (and, likewise, are converted to symbols, when loading). Assuming we used the commands above, we could expect this to be the contents of `~/.my-app-config`:
251
+
252
+ ```YAML
253
+ ---
254
+ user_data:
255
+ username: bob
256
+ ```
257
+
258
+ # Known Issues
259
+
260
+ * LoggerDelegator doesn't currently know what to do with `messenger.prompt`, so you'll have to manually log a `debug` message if you want that information logged.
261
+
262
+ # Bugs and Feature Requests
263
+
264
+ To report bugs with or suggest features/changes for CLIUtils, please use the [Issues Page](http://github.com/bachya/cli-utils/issues).
265
+
266
+ # Contributing
267
+
268
+ Contributions are welcome and encouraged. To contribute:
269
+
270
+ 1. Fork it ( http://github.com/bachya/cliutils/fork )
271
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
272
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
273
+ 4. Push to the branch (`git push origin my-new-feature`)
274
+ 5. Create new Pull Request
275
+
276
+ # License
277
+
278
+ (The MIT License)
279
+
280
+ Copyright © 2014 Aaron Bach <bachya1208@gmail.com>
281
+
282
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
283
+
284
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
285
+
286
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
287
+
288
+
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = cliutils - DESCRIBE YOUR GEM
2
+
3
+ Author:: YOUR NAME (YOUR EMAIL)
4
+ Copyright:: Copyright (c) 2014 YOUR NAME
5
+
6
+
7
+ DESCRIBE YOUR GEM HERE
8
+
9
+ == Links
10
+
11
+ * {Source on Github}[LINK TO GITHUB]
12
+ * RDoc[LINK TO RDOC.INFO]
13
+
14
+ == Install
15
+
16
+ == Examples
17
+
18
+ == Contributing
19
+
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rake/clean'
2
+ require 'rubygems'
3
+ require 'rubygems/package_task'
4
+ require 'rdoc/task'
5
+ require 'cucumber'
6
+ require 'cucumber/rake/task'
7
+ Rake::RDocTask.new do |rd|
8
+ rd.main = "README.md"
9
+ rd.rdoc_files.include("README.md","lib/**/**/*.rb")
10
+ rd.title = 'CLIUtils'
11
+ end
12
+
13
+ spec = eval(File.read('cliutils.gemspec'))
14
+
15
+ Gem::PackageTask.new(spec) do |pkg|
16
+ end
17
+ CUKE_RESULTS = 'results.html'
18
+ CLEAN << CUKE_RESULTS
19
+ desc 'Run features'
20
+ Cucumber::Rake::Task.new(:features) do |t|
21
+ opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
22
+ opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
23
+ t.cucumber_opts = opts
24
+ t.fork = false
25
+ end
26
+
27
+ desc 'Run features tagged as work-in-progress (@wip)'
28
+ Cucumber::Rake::Task.new('features:wip') do |t|
29
+ tag_opts = ' --tags ~@pending'
30
+ tag_opts = ' --tags @wip'
31
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
32
+ t.fork = false
33
+ end
34
+
35
+ task :cucumber => :features
36
+ task 'cucumber:wip' => 'features:wip'
37
+ task :wip => 'features:wip'
38
+
39
+ require 'rake/testtask'
40
+ Rake::TestTask.new do |t|
41
+ t.libs << "test"
42
+ t.test_files = FileList['test/*_test.rb']
43
+ end
44
+
45
+ task :default => [:test]
data/bin/cliutils ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ require 'cliutils.rb'
3
+
4
+ # include CLIUtils::PrettyIO
5
+ #
6
+ # warn('test')
7
+
8
+ include CLIUtils::Messenging
9
+ # #
10
+ # file_logger = Logger.new('file.txt')
11
+ # puts ''
12
+ # messenger.info('This should only appear in STDOUT.')
13
+ # messenger.attach(file_logger)
14
+ # messenger.warn('This warning should appear in STDOUT and file.txt')
15
+ # messenger.error('This error should appear in STDOUT and file.txt')
16
+ # messenger.debug('This debug message should only appear in file.txt')
17
+ # messenger.detach(file_logger)
18
+ # messenger.section('This section message should appear only in STDOUT')
19
+ # puts ''
20
+ #
21
+ include CLIUtils::Configuration
22
+
23
+ load_configuration('~/.test')
24
+ configuration.add_section(:user_data)
25
+ configuration.add_section(:program_data)
26
+ configuration.delete_section(:program_data)
27
+ configuration.user_data.merge!(username: 'bob')
28
+ configuration.save
29
+ #
30
+ # p = CLIUtils::Prefs.new(File.join(File.expand_path(File.dirname(__FILE__)),'..', 'test/test_files/prefstest.yaml'))
31
+ #
32
+ # # arr = [{:prompt=>"What is the hostname of your DD-WRT router?", :default=>"192.168.1.1", :key=>"hostname", :section=>"ssh_info"}, {:prompt=>"What is the SSH username of your DD-WRT router?", :default=>"root", :key=>"username", :section=>"ssh_info"}, {:prompt=>"What SSH port does your DD-WRT router use?", :default=>22, :key=>"port", :section=>"ssh_info"}, {:prompt=>"How do you use password or key authentication?", :default=>"password", :key=>"auth_method", :section=>"ssh_info", :options=>["password", "key"]}, {:prompt=>"Where is your key located?", :default=>"~/.ssh", :key=>"key_location", :section=>"ssh_info", :requirements=>[{:key=>"auth_method", :value=>"key"}]}, {:prompt=>"What is your password?", :key=>"password", :section=>"ssh_info", :requirements=>[{:key=>"auth_method", :value=>"password"}]}]
33
+ # # p = CLIUtils::Prefs.new(arr)
34
+ #
35
+ # # p p.prompts
36
+ # p.ask
37
+ # configuration.ingest_prefs(p)
38
+ # configuration.save
data/cliutils.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cliutils/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cliutils"
8
+ spec.version = CLIUtils::VERSION
9
+ spec.authors = ["Aaron Bach"]
10
+ spec.email = ["bachya1208@googlemail.com"]
11
+ spec.summary = 'Sugary goodness for Ruby CLI apps.'
12
+ spec.description = 'A library of functionality designed to alleviate common tasks and headaches when developing command-line (CLI) apps in Ruby.'
13
+ spec.homepage = "https://github.com/bachya/cli-utils"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.has_rdoc = true
22
+ spec.extra_rdoc_files = ['README.md']
23
+ spec.rdoc_options << '--title' << 'CLIUtils' << '--main' << 'README.md' << '-ri'
24
+
25
+ spec.add_development_dependency("bundler", "~> 1.5")
26
+ spec.add_development_dependency('rdoc', '~> 0')
27
+ spec.add_development_dependency('rake', '~> 0')
28
+ end
@@ -0,0 +1,13 @@
1
+ Feature: My bootstrapped app kinda works
2
+ In order to get going on coding my awesome app
3
+ I want to have aruba and cucumber setup
4
+ So I don't have to do it myself
5
+
6
+ Scenario: App just runs
7
+ When I get help for "cliutils"
8
+ Then the exit status should be 0
9
+ And the banner should be present
10
+ And the banner should document that this app takes options
11
+ And the following options should be documented:
12
+ |--version|
13
+ And the banner should document that this app takes no arguments
@@ -0,0 +1 @@
1
+ # Put your step definitions here
@@ -0,0 +1,16 @@
1
+ require 'aruba/cucumber'
2
+ require 'methadone/cucumber'
3
+
4
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
5
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
6
+
7
+ Before do
8
+ # Using "announce" causes massive warnings on 1.9.2
9
+ @puts = true
10
+ @original_rubylib = ENV['RUBYLIB']
11
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
12
+ end
13
+
14
+ After do
15
+ ENV['RUBYLIB'] = @original_rubylib
16
+ end