optparse-plus 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +7 -0
  6. data/CHANGES.md +66 -0
  7. data/Gemfile +5 -0
  8. data/LICENSE.txt +201 -0
  9. data/README.rdoc +173 -0
  10. data/Rakefile +94 -0
  11. data/bin/optparse_plus +130 -0
  12. data/fix.rb +29 -0
  13. data/lib/optparse-plus.rb +1 -0
  14. data/lib/optparse_plus.rb +15 -0
  15. data/lib/optparse_plus/argv_parser.rb +50 -0
  16. data/lib/optparse_plus/cli.rb +116 -0
  17. data/lib/optparse_plus/cli_logger.rb +133 -0
  18. data/lib/optparse_plus/cli_logging.rb +138 -0
  19. data/lib/optparse_plus/cucumber.rb +119 -0
  20. data/lib/optparse_plus/error.rb +32 -0
  21. data/lib/optparse_plus/execution_strategy/base.rb +34 -0
  22. data/lib/optparse_plus/execution_strategy/jvm.rb +37 -0
  23. data/lib/optparse_plus/execution_strategy/mri.rb +16 -0
  24. data/lib/optparse_plus/execution_strategy/open_3.rb +16 -0
  25. data/lib/optparse_plus/execution_strategy/open_4.rb +22 -0
  26. data/lib/optparse_plus/execution_strategy/rbx_open_4.rb +12 -0
  27. data/lib/optparse_plus/exit_now.rb +40 -0
  28. data/lib/optparse_plus/main.rb +603 -0
  29. data/lib/optparse_plus/process_status.rb +45 -0
  30. data/lib/optparse_plus/sh.rb +223 -0
  31. data/lib/optparse_plus/test/base_integration_test.rb +31 -0
  32. data/lib/optparse_plus/test/integration_test_assertions.rb +65 -0
  33. data/lib/optparse_plus/version.rb +3 -0
  34. data/optparse_plus.gemspec +28 -0
  35. data/templates/full/.gitignore.erb +4 -0
  36. data/templates/full/README.rdoc.erb +24 -0
  37. data/templates/full/Rakefile.erb +71 -0
  38. data/templates/full/_license_head.txt.erb +2 -0
  39. data/templates/full/apache_LICENSE.txt.erb +203 -0
  40. data/templates/full/bin/executable.erb +45 -0
  41. data/templates/full/custom_LICENSE.txt.erb +0 -0
  42. data/templates/full/gplv2_LICENSE.txt.erb +14 -0
  43. data/templates/full/gplv3_LICENSE.txt.erb +14 -0
  44. data/templates/full/mit_LICENSE.txt.erb +7 -0
  45. data/templates/rspec/spec/something_spec.rb.erb +5 -0
  46. data/templates/test_unit/test/integration/test_cli.rb.erb +11 -0
  47. data/templates/test_unit/test/unit/test_something.rb.erb +7 -0
  48. data/test/integration/base_integration_test.rb +60 -0
  49. data/test/integration/test_bootstrap.rb +150 -0
  50. data/test/integration/test_cli.rb +21 -0
  51. data/test/integration/test_license.rb +56 -0
  52. data/test/integration/test_readme.rb +53 -0
  53. data/test/integration/test_rspec.rb +28 -0
  54. data/test/integration/test_version.rb +21 -0
  55. data/test/unit/base_test.rb +19 -0
  56. data/test/unit/command_for_tests.sh +7 -0
  57. data/test/unit/execution_strategy/test_base.rb +24 -0
  58. data/test/unit/execution_strategy/test_jvm.rb +77 -0
  59. data/test/unit/execution_strategy/test_mri.rb +32 -0
  60. data/test/unit/execution_strategy/test_open_3.rb +70 -0
  61. data/test/unit/execution_strategy/test_open_4.rb +86 -0
  62. data/test/unit/execution_strategy/test_rbx_open_4.rb +25 -0
  63. data/test/unit/test/test_integration_test_assertions.rb +211 -0
  64. data/test/unit/test_cli_logger.rb +219 -0
  65. data/test/unit/test_cli_logging.rb +243 -0
  66. data/test/unit/test_exit_now.rb +37 -0
  67. data/test/unit/test_main.rb +840 -0
  68. data/test/unit/test_sh.rb +404 -0
  69. metadata +260 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0a6f4cc35a11290f599df1ac89b367308b7de55d367f99d882287093ecdeeefc
4
+ data.tar.gz: 96d1296f77e31242ee8f3bde8cc2b952cf57cb778fc920ba698963942394630e
5
+ SHA512:
6
+ metadata.gz: 4583ffcc8828e30bd8c633946a41ead8511b4bef0b74451328c3b4dbedcc4fdd6a380ba5d5419acf6d1a0a6ea750eb68f113c876d9035d63474004c691847839
7
+ data.tar.gz: 4cb6b962216b09ddb41f77817b2f3b9e5c086ad6b49378252ec23e1697bbe48f04b87d0213b087931dc3b2a09b1cc929a7d7f289dc7c8ef3a1a5163946e8f27d
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ html
6
+ .*.sw?
7
+ tmp
8
+ results.html
9
+ coverage
10
+ *.rbc
11
+ .DS_Store
12
+ T_KICK_THE_BASH_HABIT_WITH_RUBY_AND_METHADONE.itmsp
13
+ bin/cukedoc
14
+ methadone.wiki
15
+ tut
16
+ .idea
17
+ Session.vim
@@ -0,0 +1 @@
1
+ methadone
@@ -0,0 +1 @@
1
+ 2.5.1
@@ -0,0 +1,7 @@
1
+ notifications:
2
+ email:
3
+ on_success: always
4
+ script: 'bundle exec rake'
5
+ rvm:
6
+ - 2.4.3
7
+ - 2.5.1
@@ -0,0 +1,66 @@
1
+ # Changelog
2
+
3
+ ## v.1.3.0 - May 11, 2013
4
+
5
+ * Enhance `version` to allow for a compact form, e.g. ``version MyAPP::VERSION, :compact => true`` so that doing `--version` only shows the
6
+ app name and version, not the entire help screen. See [64].
7
+ * Allow using DSL methods before the call to `main`, even though you really shouldn't. See [65]
8
+
9
+ [64]: https://github.com/davetron5000/methadone/issues/64
10
+ [65]: https://github.com/davetron5000/methadone/issues/65
11
+
12
+ ## v.1.2.6 - Mar 10, 2013
13
+
14
+ * Need `rspec` as a real dev dependency since it's not part of Aruba any longer. See [61].
15
+
16
+ [61]: https://github.com/davetron5000/methadone/issues/61
17
+
18
+ ## v.1.2.5 - Feb 24, 2013
19
+
20
+ * Compatibility Bundler 1.3 - Bundler 1.3 bootstraps files differently than 1.2, and methadone's generated binfile ends up requiring a non-existent file. This verison works with both 1.2 and 1.3 of bundler by parsing its output to figure out which file to include.
21
+
22
+ ## v.1.2.4 - Dec 26, 2012
23
+
24
+ * Fix for my fix on apps with dashes in their name (see [59], thanks to [@terryfinn]
25
+
26
+ [@terryfinn]: https://github.com/terryfinn
27
+ [59]: https://github.com/davetron5000/methadone/pull/59
28
+
29
+ ## v.1.2.3 - Dec 8, 2012
30
+
31
+ * Can create an app with a dash in its name (See [55])
32
+ * Help switches, `-h`, and `--help` are documented in help output (See [51])
33
+ * Improve cucumber step requiring docs and fix bug where said docs had to start with a three-letter words (See [37])
34
+
35
+ [37]: http://github.com/davetron5000/methadone/issues/37
36
+ [51]: http://github.com/davetron5000/methadone/issues/51
37
+ [55]: http://github.com/davetron5000/methadone/issues/55
38
+
39
+ ## v1.2.2 - Oct 21, 2012
40
+
41
+ * Generated Rakefile has better formatted code (See [57])
42
+ * Error output preface now says "stderr is" instead of "error output", which is less confusing (See [53])
43
+ * Less scary stdout/stderr prefixing from SH, courtesy @yoni
44
+
45
+ [57]: http://github.com/davetron5000/methadone/issues/57
46
+ [53]: http://github.com/davetron5000/methadone/issues/53
47
+
48
+ ## v1.2.1 - Jun 10, 2012, 3:41 PM
49
+
50
+ * Slightly loosen what passes for a one-line description of the app, courtesy @jredville
51
+
52
+ ## v1.2.0 - May 21, 2012, 11:05 PM
53
+
54
+ * Better handling of `open4` dependency when you don't install it and you don't use it.
55
+ * Quoted spaced strings in config files and env var weren't working. Now they are.
56
+ * Use the current version in generated gemspec
57
+ * Non-string arguments (such as Regexps for validation and classes for type conversion) were not working. Now they are.
58
+ * `sh` can now be used more safely by passing an array to avoid tokenization (thanks @gchpaco!)
59
+
60
+ ## v1.1.0 - April 21, 2012, 6:00 PM
61
+
62
+ * Can bootstrap apps using RSpec instead of Test::Unit (thanks @msgehard)
63
+
64
+ ## v1.0.0 - April 1, 2012, 10:31
65
+
66
+ * Initial official release
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'http://www.rubygems.org'
2
+
3
+ gem 'open4', :platform => :ruby_18
4
+ gem 'test-unit'
5
+ gemspec
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,173 @@
1
+ = optparse-plus - Wrapper around OptionParse to Make CLIs a bit Easier
2
+
3
+ Author:: Dave Copeland (mailto:davetron5000 at g mail dot com)
4
+ Copyright:: Copyright (c) 2011 by Dave Copeland
5
+ License:: Distributes under the Apache License, see LICENSE.txt in the source distro
6
+
7
+ A smattering of tools to make your command-line apps easily awesome; Ideally makes it almost as easy as bash to get a command line app up and running.
8
+
9
+ The goal of this project is to make it as easy as possible to write awesome and powerful command-line applications.
10
+
11
+ Toward that end, this gem provides:
12
+
13
+ * A command-line app to bootstrap a new command-line app.
14
+ * A lightweight DSL to create your command-line interface, that loses none of <tt>OptionParser</tt>'s power.
15
+ * A simplified means of running external commands that has better error handling and diagnostics.
16
+ * Simplified zero-config logging that is a better-than-<tt>puts</tt> <tt>puts</tt>.
17
+ * Support for integration-testing your CLI using Test::Unit
18
+
19
+ == Platforms
20
+
21
+ This library only supports the latest versions of Ruby. JRuby support has been too difficult to keep up with, though the library should work for JRuby.
22
+
23
+ See the {Travis config file}[./.travis.yml] for specifics.
24
+
25
+ == Bootstrapping a new CLI App
26
+
27
+ The +optparse_plus+ command-line app will bootstrap a new command-line app, setting up a proper gem structure, unit tests, and integration tests.
28
+
29
+ It assumes you are using a standard Ruby development environment, which includes:
30
+
31
+ * Some sort of Ruby version manager to allow you to manage Ruby as yourself and not as root/system
32
+ * Bundler
33
+ * Git
34
+
35
+ _(Note that apps *powered* by this gem have no particular runtime dependencies as classes this gem provides depend only on the standard library)_
36
+
37
+
38
+ $ optparse_plus --help
39
+ Usage: optparse_plus [options] app_name
40
+
41
+ Kick the bash habit by bootstrapping your Ruby command-line apps
42
+
43
+ v2.0.0
44
+
45
+ Options:
46
+ -h, --help Show command line help
47
+ --force Overwrite files if they exist
48
+ --[no-]readme [Do not ]produce a README file
49
+ --rspec Generate RSpec unit tests instead of Test::Unit
50
+ -l, --license LICENSE Specify the license for your project
51
+ (mit|apache|gplv2|gplv3|custom|NONE)
52
+ --log-level LEVEL Set the logging level
53
+ (debug|info|warn|error|fatal)
54
+ (Default: info)
55
+ --version Show help/version info
56
+
57
+ Arguments:
58
+
59
+ app_name
60
+ Name of your app, which is used for the gem name and executable name
61
+
62
+
63
+
64
+
65
+
66
+ Usage: optparse_plus [options] app_name
67
+ --force Overwrite files if they exist
68
+ $ optparse_plus myapp -l mit
69
+ $ cd myapp
70
+ $ bundle install
71
+ ...
72
+ $ bundle exec rake
73
+ Started
74
+ .
75
+ Finished in 0.000499 seconds.
76
+ -----------------------------------------------------------------------------------------
77
+ 1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
78
+ 100% passed
79
+ -----------------------------------------------------------------------------------------
80
+ 2004.01 tests/s, 2004.01 assertions/s
81
+ Started
82
+ .
83
+ Finished in 0.298281 seconds.
84
+ -----------------------------------------------------------------------------------------
85
+ 1 tests, 8 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
86
+ 100% passed
87
+ -----------------------------------------------------------------------------------------
88
+ 3.35 tests/s, 26.82 assertions/s
89
+
90
+ $ cat test/integration/test_cli.rb
91
+ require "optparse_plus/test/base_integration_test"
92
+
93
+ class TestSomething < OptparsePlus::BaseIntegrationTest
94
+ def test_truth
95
+ stdout,stderr,results = run_app("myapp","--help")
96
+ assert_banner(stdout, "myapp", takes_options: true, takes_arguments: false)
97
+ assert_option(stdout,"-h", "--help")
98
+ assert_option(stdout,"--version")
99
+ assert_oneline_summary(stdout)
100
+ end
101
+ end
102
+
103
+
104
+ Basically, this sets you up with all the boilerplate that you *should* be using to write a command-line app. Specifically, you get:
105
+
106
+ * Gemified project (based on <tt>bundle gem</tt>)
107
+ * An executable using OptparsePlus::Main to outline your new app
108
+ * <tt>Test::Unit</tt> test task set up and an empty unit test.
109
+ * <tt>Test::Unit</tt> integration tests with some of optparse-plus's assertions to let you drive your CLI's development
110
+ * The outline of a README
111
+ * An optional license included
112
+
113
+ == DSL for your <tt>bin</tt> file
114
+
115
+ A canonical <tt>OptionParser</tt>-driven app has a few problems with it structurally that optparse-plus can solve:
116
+
117
+ * Backwards organization - main logic is at the bottom of the file, not the top
118
+ * Verbose to use +opts.on+ just to set a value in a +Hash+
119
+ * No exception handling - you have to explicitly call <tt>exit</tt> and/or let exceptions' stack traces leak through.
120
+
121
+ optparse-plus provides OptparsePlus::Main to help make a clean and easy-to-maintain <tt>bin</tt> file. See the {rdoc}[http://davetron5000.github.com/optparse-plus/rdoc/classes/OptparsePlus/Main.html] for an example, and see {my blog}[http://www.naildrivin5.com/blog/2011/12/19/methadone-the-awesome-cli-library.html] on the derivation of this module.
122
+
123
+ == Wrapper for running external commands with good logging
124
+
125
+ While backtick and <tt>%x[]</tt> are nice for compact, bash-like scripting, they have some failings:
126
+
127
+ * You have to check the return value via <tt>$?</tt>
128
+ * You have no access to the standard error
129
+ * You really want to log: the command, the output, and the error so that for cron-like tasks, you can sort out what happened
130
+
131
+ Enter OptparsePlus::SH
132
+
133
+ sh "cp foo.txt /tmp"
134
+ # => logs command at DEBUG level
135
+ # if the command exited zero:
136
+ # logs the standard output at DEBUG
137
+ # logs the standard error at WARN
138
+ # if the command exited nonzero:
139
+ # logs the standard output at INFO
140
+ # logs the standard error at WARN
141
+ # returns the exit code for your examination
142
+ #
143
+ # there's a LOT MORE
144
+
145
+ See the {rdoc}[http://davetron5000.github.com/optparse-plus/rdoc/classes/OptparsePlus/SH.html] for more detailed examples and usage.
146
+
147
+ This isn't a replacement for Open3 or ChildProcess, but a way to easily "do the right thing" for most cases.
148
+
149
+ == Zero-Config Logging
150
+
151
+ Chances are, your code is littered with <tt>STDERR.puts</tt> on a good day, and nothing on a bad day. You probably also have a bunch of debug <tt>puts</tt> calls that you have commented out. Logging is extremely helpful in understanding how your app is behaving (or how it behaved in the past). Logging can be a pain to set up, and can also make it hard to give the user at the command-prompt a good experience.
152
+
153
+ OptparsePlus::CLILogger is designed to handle this. It's a proper subclass of Ruby's built-in <tt>Logger</tt> with a few enhancements:
154
+
155
+ * Messages don't get formatting if they are destined for a TTY (e.g. the user sitting at her terminal)
156
+ * Errors and warnings go to the standard error.
157
+ * Debug and info messages go to the standard output.
158
+ * When these are redirected to a file, the log messages are properly date/time stamped as you'd expect
159
+ * You can mix-in OptparsePlus::CLILogging to get access to a global logger instances without resorting to an explicit global variable
160
+
161
+ See {CLILogger's rdoc}[http://davetron5000.github.com/optparse-plus/rdoc/classes/OptparsePlus/CLILogger.html] and then {CLILogging's}[http://davetron5000.github.com/optparse-plus/rdoc/classes/OptparsePlus/CLILogging.html] for more.
162
+
163
+ Currently, there are classes that assist in directing output logger-style to the right place; basically ensuring that errors go to +STDERR+ and everything else goes to +STDOUT+. All of this is, of course, configurable
164
+
165
+ == Integration Tests
166
+
167
+ optparse-plus provides some basic features for executing your CLI and asserting things about it. OptparsePlus::Test::IntegrationTestAssertions documents these.
168
+
169
+ == Contributing
170
+
171
+ * Feel free to file an issue, even if you don't have time to submit a patch
172
+ * Please try to include a test for any patch you submit. If you don't include a test, I'll have to write one, and it'll take longer to get your code in.
173
+ * This is not intended to support “command-suite” style CLIs. See {GLI}[http://naildrivin5.com/gli] if that's what you want.