methadone-rehab 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +11 -0
  6. data/CHANGES.md +66 -0
  7. data/Gemfile +6 -0
  8. data/LICENSE.txt +201 -0
  9. data/README.rdoc +179 -0
  10. data/Rakefile +98 -0
  11. data/TODO.md +3 -0
  12. data/bin/methadone +157 -0
  13. data/features/bootstrap.feature +169 -0
  14. data/features/license.feature +43 -0
  15. data/features/multilevel_commands.feature +125 -0
  16. data/features/readme.feature +26 -0
  17. data/features/rspec_support.feature +27 -0
  18. data/features/step_definitions/bootstrap_steps.rb +47 -0
  19. data/features/step_definitions/license_steps.rb +30 -0
  20. data/features/step_definitions/readme_steps.rb +26 -0
  21. data/features/step_definitions/version_steps.rb +4 -0
  22. data/features/support/env.rb +26 -0
  23. data/features/version.feature +17 -0
  24. data/lib/methadone.rb +15 -0
  25. data/lib/methadone/argv_parser.rb +50 -0
  26. data/lib/methadone/cli.rb +124 -0
  27. data/lib/methadone/cli_logger.rb +133 -0
  28. data/lib/methadone/cli_logging.rb +138 -0
  29. data/lib/methadone/cucumber.rb +174 -0
  30. data/lib/methadone/error.rb +32 -0
  31. data/lib/methadone/execution_strategy/base.rb +34 -0
  32. data/lib/methadone/execution_strategy/jvm.rb +37 -0
  33. data/lib/methadone/execution_strategy/mri.rb +16 -0
  34. data/lib/methadone/execution_strategy/open_3.rb +16 -0
  35. data/lib/methadone/execution_strategy/open_4.rb +22 -0
  36. data/lib/methadone/execution_strategy/rbx_open_4.rb +12 -0
  37. data/lib/methadone/exit_now.rb +40 -0
  38. data/lib/methadone/main.rb +1039 -0
  39. data/lib/methadone/process_status.rb +45 -0
  40. data/lib/methadone/sh.rb +223 -0
  41. data/lib/methadone/version.rb +3 -0
  42. data/methadone-rehab.gemspec +32 -0
  43. data/templates/full/.gitignore.erb +4 -0
  44. data/templates/full/README.rdoc.erb +25 -0
  45. data/templates/full/Rakefile.erb +74 -0
  46. data/templates/full/_license_head.txt.erb +2 -0
  47. data/templates/full/apache_LICENSE.txt.erb +203 -0
  48. data/templates/full/bin/executable.erb +47 -0
  49. data/templates/full/custom_LICENSE.txt.erb +0 -0
  50. data/templates/full/features/executable.feature.erb +13 -0
  51. data/templates/full/features/step_definitions/executable_steps.rb.erb +1 -0
  52. data/templates/full/features/support/env.rb.erb +16 -0
  53. data/templates/full/gplv2_LICENSE.txt.erb +14 -0
  54. data/templates/full/gplv3_LICENSE.txt.erb +15 -0
  55. data/templates/full/mit_LICENSE.txt.erb +7 -0
  56. data/templates/multicommand/bin/executable.erb +52 -0
  57. data/templates/multicommand/lib/command.rb.erb +40 -0
  58. data/templates/multicommand/lib/commands.rb.erb +7 -0
  59. data/templates/rspec/spec/something_spec.rb.erb +5 -0
  60. data/templates/test_unit/test/tc_something.rb.erb +7 -0
  61. data/test/base_test.rb +20 -0
  62. data/test/command_for_tests.sh +7 -0
  63. data/test/execution_strategy/test_base.rb +24 -0
  64. data/test/execution_strategy/test_jvm.rb +77 -0
  65. data/test/execution_strategy/test_mri.rb +32 -0
  66. data/test/execution_strategy/test_open_3.rb +70 -0
  67. data/test/execution_strategy/test_open_4.rb +86 -0
  68. data/test/execution_strategy/test_rbx_open_4.rb +25 -0
  69. data/test/test_cli_logger.rb +219 -0
  70. data/test/test_cli_logging.rb +243 -0
  71. data/test/test_exit_now.rb +37 -0
  72. data/test/test_main.rb +1213 -0
  73. data/test/test_multi.rb +405 -0
  74. data/test/test_sh.rb +404 -0
  75. metadata +321 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c85cf7a8418718705b69986c132465634b291113
4
+ data.tar.gz: a06acd9930ae15966ad17327cf7c6b1c2e6d99fc
5
+ SHA512:
6
+ metadata.gz: 8a385620a8e2d2fdbaf1da44544c8431b7b29f8e54cd2ed6ff224a1817fddc2fc13fc9a6660be7b2813ed4ace6b5b48536ebcfb6cfc2b196f686b2d71f535599
7
+ data.tar.gz: b023b825c424e7006d0937a9f17b1d2a9a83aee2cbf398aa2d08dfc6d180aef927e301dad5e4d0e5df1c536396d3a3be41a3148011578bdcabef2f8adc0436e2
@@ -0,0 +1,15 @@
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
@@ -0,0 +1 @@
1
+ methadone-rehab
@@ -0,0 +1 @@
1
+ 2.2.2
@@ -0,0 +1,11 @@
1
+ notifications:
2
+ email:
3
+ on_success: always
4
+ script: 'bundle exec rake'
5
+ rvm:
6
+ - 1.9.3
7
+ - 2.0.0
8
+ - 2.1.0
9
+ - 2.2.0
10
+ - 2.2.2
11
+ - jruby-19mode
@@ -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,6 @@
1
+ source 'http://www.rubygems.org'
2
+
3
+ gem 'open4', :platform => :ruby_18
4
+ gem 'test-unit'
5
+ # Specify your gem's dependencies in methadone.gemspec
6
+ 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,179 @@
1
+ = Methadone - kick the bash habit and start your command line apps off right
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
+ {<img src="https://secure.travis-ci.org/enemy/methadone-rehab.png" alt="Build Status" />}[http://travis-ci.org/enemy/methadone-rehab]
8
+
9
+ A smattering of tools to make your command-line apps easily awesome; kick the bash habit without sacrificing any of the power.
10
+
11
+ The goal of this project is to make it as easy as possible to write awesome and powerful command-line applications.
12
+
13
+ Toward that end, this gem provides:
14
+
15
+ * A command-line app to bootstrap a new command-line app.
16
+ * A lightweight DSL to create your command-line interface, that loses none of <tt>OptionParser</tt>'s power.
17
+ * A simplified means of running external commands that has better error handling and diagnostics.
18
+ * Simplified zero-config logging that is a better-than-<tt>puts</tt> <tt>puts</tt>.
19
+ * Cucumber Steps, built on Aruba, to allow you to test-drive your command-line app development.
20
+
21
+ === Methadone Rehab 1.9.1
22
+
23
+ TODO
24
+
25
+ === Methadone Clinic 1.0
26
+
27
+ Building onto the great foundation that is Methadone 1.3, contributor {Dennis Bell}[http://github.com/dennisjbell/methadone] added the following functionality
28
+
29
+ * Option mutual exclusiveness and dependency
30
+ * A missing feature of OptionParser, you can now specify that an option requires another option be used, or specify you cannot use certain options together
31
+ * Subcommands
32
+ * Allows complex applications to have subcommands in separate files, improving its modularity and maintainability
33
+ * See {Subcommand section}[https://github.com/dennisjbell/methadone/blob/master/lib/methadone/main.rb#L72-L116] in the <tt>Methadone::Main</tt> module for more details
34
+ * Argument filters and smart allocation
35
+ * Allows arguments to meet filter requirements like options
36
+ * Allocation of arguments are now as-needed, providing values to arguments that need an argument before filling the first greedy argument with the rest of the available values
37
+ * Values left in <tt>ARGV</tt> are no longer lost; they now remain in <tt>ARGV</tt> for your application to access.
38
+ * Convenience method <tt>help_if_bare</tt> that if specified, calling your app with no arguments will print help -- very usefull on a multi-level-command based application
39
+ * <tt>version</tt> now takes optional symbolic arguments of :terse and :basic, providing just the version number or the file and version number respectively
40
+
41
+ Most, if not all, of these improvements will be merged into the base Methadone project in the near future.
42
+
43
+
44
+ == Tutorial
45
+
46
+ http://a1.mzstatic.com/us/r30/Publication/v4/2c/f7/90/2cf7902f-f709-9125-c73d-87311216527d/MethadoneTutorial.225x225-75.jpg
47
+
48
+ {Tutorial for your iPad}[http://itunes.apple.com/us/book/kick-bash-habit-ruby-methadone/id515825242?ls=1] - This is a *free* iBooks interactive ebook that contains a step-by-step tutorial on making an awesome app with Methadone, including screencasts.
49
+
50
+ == Links
51
+
52
+ * {Source on Github}[http://github.com/davetron5000/methadone]
53
+ * RDoc[http://davetron5000.github.com/methadone/rdoc]
54
+
55
+ == Platforms
56
+
57
+ * The build runs on Travis for:
58
+ * MRI Ruby 1.9.2
59
+ * MRI Ruby 1.9.3
60
+ * MRI Ruby 2.0.0
61
+ * MRI Ruby 2.1.0
62
+ * JRuby in both 1.8 and 1.9 mode
63
+
64
+ == Bootstrapping a new CLI App
65
+
66
+ The +methadone+ command-line app will bootstrap a new command-line app, setting up a proper gem structure, unit tests, and cucumber-based tests with aruba:
67
+
68
+ $ methadone --help
69
+ Usage: methadone [options] app_name
70
+ --force Overwrite files if they exist
71
+ $ methadone newgem
72
+ $ cd newgem
73
+ $ bundle
74
+ $ rake
75
+ 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
76
+ 1 scenario (1 passed)
77
+ 3 steps (3 passed)
78
+ $ cat features/newgem.feature
79
+ Feature: My bootstrapped app kinda works
80
+ In order to get going on coding my awesome app
81
+ I want to have aruba and cucumber setup
82
+ So I don't have to do it myself
83
+
84
+ Scenario: App just runs
85
+ When I run `newgem --help`
86
+ Then the exit status should be 0
87
+ And the output should contain:
88
+ """
89
+ Usage: newgem [options]
90
+ """
91
+
92
+ Basically, this sets you up with all the boilerplate that you *should* be using to write a command-line app. Specifically, you get:
93
+
94
+ * Gemified project (based on <tt>bundle gem</tt>)
95
+ * An executable using Methadone::Main to outline your new app
96
+ * <tt>Test::Unit</tt> test task set up and an empty unit test.
97
+ * Aruba/Cucumber set up with a basic feature that exercise your executable
98
+ * The outline of a README
99
+ * An optional license included
100
+
101
+ == DSL for your <tt>bin</tt> file
102
+
103
+ A canonical <tt>OptionParser</tt> driven app has a few problems with it structurally that Methadone can solve:
104
+
105
+ * Backwards organization - main logic is at the bottom of the file, not the top
106
+ * Verbose to use +opts.on+ just to set a value in a +Hash+
107
+ * No exception handling - you have to explicitly call <tt>exit</tt> and/or let exceptions' stack traces leak through.
108
+
109
+ Methadone provides Methadone::Main to help make a clean and easy-to-maintain <tt>bin</tt> file. See the {rdoc}[http://davetron5000.github.com/methadone/rdoc/classes/Methadone/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.
110
+
111
+ == Wrapper for running external commands with good logging
112
+
113
+ While backtick and <tt>%x[]</tt> are nice for compact, bash-like scripting, they have some failings:
114
+
115
+ * You have to check the return value via <tt>$?</tt>
116
+ * You have no access to the standard error
117
+ * You really want to log: the command, the output, and the error so that for cron-like tasks, you can sort out what happened
118
+
119
+ Enter Methadone::SH
120
+
121
+ sh "cp foo.txt /tmp"
122
+ # => logs command at DEBUG level
123
+ # if the command exited zero:
124
+ # logs the standard output at DEBUG
125
+ # logs the standard error at WARN
126
+ # if the command exited nonzero:
127
+ # logs the standard output at INFO
128
+ # logs the standard error at WARN
129
+ # returns the exit code for your examination
130
+ #
131
+ # there's a LOT MORE
132
+
133
+ See the {rdoc}[http://davetron5000.github.com/methadone/rdoc/classes/Methadone/SH.html] for more detailed examples and usage.
134
+
135
+ This isn't a replacement for Open3 or ChildProcess, but a way to easily "do the right thing" for most cases.
136
+
137
+ == Zero-Config Logging
138
+
139
+ 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 understand 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.
140
+
141
+ Methadone::CLILogger is designed to handle this. It's a proper subclass of Ruby's built-in <tt>Logger</tt> with a few enhancements:
142
+
143
+ * Messages don't get formatting if they are destined for a TTY (e.g. the user sitting at her terminal)
144
+ * Errors and warnings go to the standard error.
145
+ * Debug and info messages go to the standard output.
146
+ * When these are redirected to a file, the log messages are properly date/time stamped as you'd expect
147
+ * You can mix-in Methadone::CLILogging to get access to a global logger instances without resorting to an explicit global variable
148
+
149
+ See {CLILogger's rdoc}[http://davetron5000.github.com/methadone/rdoc/classes/Methadone/CLILogger.html] and then {CLILogging's}[http://davetron5000.github.com/methadone/rdoc/classes/Methadone/CLILogging.html] for more.
150
+
151
+
152
+ 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
153
+
154
+ == Cucumber Steps
155
+
156
+ Methadone uses aruba[http://www.github.com/cucumber/aruba] for BDD-style testing with cucumber. This library has some awesome steps, and Methadone provides additional, more opinionated, steps.
157
+
158
+ === Example
159
+
160
+ Here's an example from methadone's own tests:
161
+
162
+ Scenario: Help is properly documented
163
+ When I get help for "methadone"
164
+ Then the exit status should be 0
165
+ And the following options should be documented:
166
+ |--force|
167
+ And the banner should be present
168
+ And the banner should include the version
169
+ And the banner should document that this app takes options
170
+ And the banner should document that this app's arguments are:
171
+ |app_name|which is required|
172
+ |dir_name|which is optional|
173
+
174
+ See Methadone::Cucumber or its {rdoc}[http://davetron5000.github.com/methadone/rdoc/classes/Methadone/Cucumber.html] for a list of all the steps provided.
175
+
176
+ == Contributing
177
+
178
+ * Feel free to file an issue, even if you don't have time to submit a patch
179
+ * 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.