methadone 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ script: 'bundle exec rake'
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 1.8.7
6
+ - ree
7
+ - ruby-head
8
+ - rbx
@@ -78,6 +78,10 @@ Methadone gives you a simple,lightweight DSL to help. It's important to note th
78
78
 
79
79
  # If something goes wrong, you can just raise an exception
80
80
  # or call exit_now! if you want to control the exit status
81
+ #
82
+ # Note that if you set DEBUG in the environment, the exception
83
+ # will leak through; this can be handy to figure out why
84
+ # your app might be failing
81
85
  end
82
86
 
83
87
  description "One line summary of your awesome app"
@@ -162,6 +166,7 @@ Here's an example from methadone's own tests:
162
166
  And the following options should be documented:
163
167
  |--force|
164
168
  And the banner should be present
169
+ And the banner should include the version
165
170
  And the banner should document that this app takes options
166
171
  And the banner should document that this app's arguments are:
167
172
  |app_name|which is required|
@@ -186,6 +191,10 @@ Here's an example from methadone's own tests:
186
191
 
187
192
  Then the banner should be present
188
193
 
194
+ * Checks that the banner includes the version
195
+
196
+ Then the banner should include the version
197
+
189
198
  * Checks that the usage banner indicates it takes options via <tt>[options]</tt>
190
199
 
191
200
  Then the banner should document that this app takes options
data/Rakefile CHANGED
@@ -35,6 +35,13 @@ Cucumber::Rake::Task.new(:features) do |t|
35
35
  t.fork = false
36
36
  end
37
37
 
38
+ Cucumber::Rake::Task.new('features:wip') do |t|
39
+ tag_opts = ' --tags ~@pending'
40
+ tag_opts = ' --tags @wip'
41
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
42
+ t.fork = false
43
+ end
44
+
38
45
  CLEAN << "coverage"
39
46
 
40
47
  task :default => [:test, :features]
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby -w
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  require 'fileutils'
4
4
  require 'optparse'
@@ -14,6 +14,8 @@ main do |app_name|
14
14
  using_readme = options[:readme]
15
15
 
16
16
  gemname = File.basename(app_name)
17
+ module_name = gemname.split(/_/).map(&:capitalize).join('')
18
+
17
19
  debug "Creating project for gem #{gemname}"
18
20
 
19
21
  chdir File.dirname(app_name)
@@ -28,13 +30,21 @@ main do |app_name|
28
30
  copy_file file, :binding => binding
29
31
  end
30
32
 
33
+ license = options[:license]
34
+ if license
35
+ copy_file "#{options[:license]}_LICENSE.txt", :as => "LICENSE.txt"
36
+ else
37
+ warn "your app has no license"
38
+ end
39
+
40
+
31
41
  if using_readme
32
42
  copy_file "README.rdoc", :binding => binding
33
43
  end
34
44
 
35
45
  copy_file "features/executable.feature", :as => "#{gemname}.feature", :binding => binding
36
46
  copy_file "features/step_definitions/executable_steps.rb", :as => "#{gemname}_steps.rb"
37
- copy_file "bin/executable", :as => gemname, :executable => true
47
+ copy_file "bin/executable", :as => gemname, :executable => true, :binding => binding
38
48
 
39
49
  add_to_file "#{gemname}.gemspec", [
40
50
  " s.add_development_dependency('rdoc')",
@@ -51,7 +61,12 @@ description "Kick the bash habit by bootstrapping your Ruby command-line apps"
51
61
  on("--force","Overwrite files if they exist")
52
62
  on("--[no-]readme","[Do not ]produce a README file")
53
63
 
64
+ licenses = %w(mit apache custom)
65
+ on("-l LICENSE","--license",licenses,"Specify the license for your project (#{licenses.join('|')})")
66
+
54
67
  arg :app_name, :required
55
68
 
69
+ version Methadone::VERSION
70
+
56
71
  go!
57
72
 
@@ -37,9 +37,11 @@ Feature: Bootstrap a new command-line app
37
37
  And the file "tmp/newgem/newgem.gemspec" should match /add_dependency\('methadone'/
38
38
  Given I cd to "tmp/newgem"
39
39
  And my app's name is "newgem"
40
- When I successfully run `bin/newgem --help`
40
+ When I successfully run `bin/newgem --help` with "lib" in the library path
41
41
  Then the banner should be present
42
- And the banner should document that this app takes no options
42
+ And the banner should document that this app takes options
43
+ And the following options should be documented:
44
+ |--version|
43
45
  And the banner should document that this app takes no arguments
44
46
  When I successfully run `rake -T -I../../lib`
45
47
  Then the output should contain:
@@ -61,7 +63,7 @@ Feature: Bootstrap a new command-line app
61
63
  And the output should contain:
62
64
  """
63
65
  1 scenario (1 passed)
64
- 5 steps (5 passed)
66
+ 6 steps (6 passed)
65
67
  """
66
68
 
67
69
  Scenario: Won't squash an existing dir
@@ -1,27 +1,32 @@
1
- @pending
2
1
  Feature: Users should get the license included
3
2
  As a user
4
3
  I'd like to be able to include a license
5
4
  So that I don't have to hunt it down for every new project
6
5
 
7
- Scenario: Use a custom license
8
- Given a custom license is available at http://localhost:1234/my_license.txt
9
- When I run successfully `methadone -l my_license --license-location=http://localhost:1234 newgem`
10
- Then newgem's license should identical to the file at http://localhost:1234/my_license.txt
11
- And the README should reference the license my_license
6
+ Background:
7
+ Given the directory "tmp/newgem" does not exist
8
+
9
+ Scenario: Use a non-stock license
10
+ When I successfully run `methadone -l custom tmp/newgem`
11
+ Then newgem's license should be an empty file
12
+ And the README should reference the need for a license
12
13
 
13
14
  Scenario Outline: Include one of a few stock licenses
14
- When I run successfully `methadone -l <license> newgem`
15
+ When I successfully run `methadone -l <license> tmp/newgem`
15
16
  Then newgem's license should be the <license> license
16
17
  And the README should reference this license
17
18
 
18
19
  Examples:
19
- |<license>|
20
+ |license|
20
21
  |apache|
21
- |gpl|
22
22
  |mit|
23
23
 
24
+ Scenario: We only support a few licenses
25
+ When I run `methadone -l foobar tmp/newgem`
26
+ Then the exit status should not be 0
27
+ And the stderr should match /invalid argument: -l foobar/
28
+
24
29
  Scenario: No license specified
25
- When I run successfully `methadone newgem`
26
- Then the stderr should contain "Warning: your app has no license"
30
+ When I successfully run `methadone tmp/newgem`
31
+ Then the stderr should contain "your app has no license"
27
32
  And the README should not reference a license
@@ -0,0 +1,24 @@
1
+ Then /^the README should not reference a license$/ do
2
+ step %(the file "tmp/newgem/README.rdoc" should not match /[Ll]icense/)
3
+ end
4
+
5
+ Then /^newgem's license should be the (\w+) license/ do |license|
6
+ @license = license
7
+ step %(a file named "tmp/newgem/LICENSE.txt" should exist)
8
+ end
9
+
10
+ Then /^the README should reference this license$/ do
11
+ step %(the file "tmp/newgem/README.rdoc" should match /License::/)
12
+ step %(the file "tmp/newgem/README.rdoc" should match /#{@license}/)
13
+ end
14
+
15
+
16
+ Then /^newgem's license should be an empty file$/ do
17
+ step %(a file named "tmp/newgem/LICENSE.txt" should exist)
18
+ File.read("tmp/aruba/tmp/newgem/LICENSE.txt").should == "\n"
19
+ end
20
+
21
+ Then /^the README should reference the need for a license$/ do
22
+ step %(the file "tmp/newgem/README.rdoc" should match /License:: INSERT LICENSE HERE/)
23
+ end
24
+
@@ -0,0 +1,4 @@
1
+ When /^I successfully run `([^`]*)` with "([^"]*)" in the library path$/ do |command,dir|
2
+ ENV["RUBYOPT"] = "-I" + File.join(Dir.pwd,ARUBA_DIR,'tmp','newgem',dir)
3
+ step %(I successfully run `#{command}`)
4
+ end
@@ -0,0 +1,17 @@
1
+ @wip
2
+ Feature: The version should show up in the banner by default
3
+ As a developer
4
+ I should be able to have the current gem version in the banner
5
+ So I don't have to maintain it in two places
6
+ And so users can easily see the version from the app itself
7
+
8
+ Scenario Outline: Show the gem version
9
+ Given I successfully run `methadone tmp/newgem`
10
+ When I cd to "tmp/newgem"
11
+ And I successfully run `bin/newgem <flag>` with "lib" in the library path
12
+ Then the banner should include the version
13
+
14
+ Examples:
15
+ |flag |
16
+ |--help |
17
+ |--version |
@@ -32,7 +32,7 @@ module Methadone
32
32
  # Change the global logger that includers will use. Useful if you
33
33
  # don't want the default configured logger.
34
34
  #
35
- # +new_logger+:: the new logger. May not be nil and should be a a logger of some kind
35
+ # +new_logger+:: the new logger. May not be nil and should be a logger of some kind
36
36
  def logger=(new_logger)
37
37
  raise ArgumentError,"Logger may not be nil" if new_logger.nil?
38
38
  @@logger = new_logger
@@ -36,7 +36,11 @@ Then /^the banner should document that this app takes no options$/ do
36
36
  end
37
37
 
38
38
  Then /^the banner should document that this app takes no arguments$/ do
39
- step %(the output should match /Usage: #{@app_name}\\s*$/)
39
+ step %(the output should match /Usage: #{@app_name}\\s*\(\\[options\\]\)?$/)
40
+ end
41
+
42
+ Then /^the banner should include the version$/ do
43
+ step %(the output should match /v\\d+\\.\\d+\\.\\d+/)
40
44
  end
41
45
 
42
46
  Then /^there should be a one line summary of what the app does$/ do
@@ -1,7 +1,7 @@
1
1
  require 'optparse'
2
2
 
3
3
  begin
4
- basic_object = Module.const_get('BasicObject')
4
+ Module.const_get('BasicObject')
5
5
  # We are 1.9.x
6
6
  rescue NameError
7
7
  BasicObject = Object
@@ -112,6 +112,7 @@ module Methadone
112
112
  # 64 and a message about that missing argument.
113
113
  #
114
114
  def go!
115
+ normalize_defaults
115
116
  opts.parse!
116
117
  opts.check_args!
117
118
  result = call_main
@@ -122,6 +123,8 @@ module Methadone
122
123
  end
123
124
  rescue OptionParser::ParseError => ex
124
125
  error ex.message
126
+ puts
127
+ puts opts.help
125
128
  exit 64 # Linux standard for bad command line
126
129
  end
127
130
 
@@ -197,15 +200,47 @@ module Methadone
197
200
  @options
198
201
  end
199
202
 
203
+ # Set the version of your app so it appears in the
204
+ # banner. This also adds --version as an option to your app which,
205
+ # when used, will act just like --help
206
+ #
207
+ # version - the current version of your app. Should almost always be
208
+ # YourApp::VERSION, where the module YourApp should've been generated
209
+ # by the bootstrap script
210
+ # custom_message - if provided, customized the message shown next to --version
211
+ def version(version,custom_message='Show help/version info')
212
+ opts.version(version)
213
+ opts.on("--version",custom_message) do
214
+ puts opts.to_s
215
+ exit 0
216
+ end
217
+ end
218
+
200
219
  private
201
220
 
221
+ # Normalized all defaults to both string and symbol forms, so
222
+ # the user can access them via either means just as they would for
223
+ # non-defaulted options
224
+ def normalize_defaults
225
+ new_options = {}
226
+ options.each do |key,value|
227
+ unless value.nil?
228
+ new_options[key.to_s] = value
229
+ new_options[key.to_sym] = value
230
+ end
231
+ end
232
+ options.merge!(new_options)
233
+ end
234
+
202
235
  # Handle calling main and trapping any exceptions thrown
203
236
  def call_main
204
237
  @main_block.call(*ARGV)
205
238
  rescue Methadone::Error => ex
239
+ raise ex if ENV['DEBUG']
206
240
  error ex.message unless no_message? ex
207
241
  ex.exit_code
208
242
  rescue => ex
243
+ raise ex if ENV['DEBUG']
209
244
  raise ex if @leak_exceptions
210
245
  error ex.message unless no_message? ex
211
246
  70 # Linux sysexit code for internal software error
@@ -233,6 +268,7 @@ module Methadone
233
268
  @args = []
234
269
  @arg_options = {}
235
270
  @description = nil
271
+ @version = nil
236
272
  set_banner
237
273
  end
238
274
 
@@ -301,6 +337,12 @@ module Methadone
301
337
  @option_parser.to_s
302
338
  end
303
339
 
340
+ # Sets the version for the banner
341
+ def version(version)
342
+ @version = version
343
+ set_banner
344
+ end
345
+
304
346
  private
305
347
 
306
348
  def set_banner
@@ -322,6 +364,7 @@ module Methadone
322
364
  }.join(' ')
323
365
  end
324
366
  new_banner += "\n\n#{@description}" if @description
367
+ new_banner += "\n\nv#{@version}" if @version
325
368
  new_banner += "\n\nOptions:" if @accept_options
326
369
 
327
370
  @option_parser.banner=new_banner
@@ -1,3 +1,3 @@
1
1
  module Methadone
2
- VERSION = "0.3.4"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -2,7 +2,13 @@
2
2
 
3
3
  Author:: YOUR NAME (YOUR EMAIL)
4
4
  Copyright:: Copyright (c) <%= Time.now.year %> YOUR NAME
5
- License::
5
+ <% if license %>
6
+ <% if license == 'custom' %>
7
+ License:: INSERT LICENSE HERE
8
+ <% else %>
9
+ License:: <%= license %>, see LICENSE.txt
10
+ <% end %>
11
+ <% end %>
6
12
 
7
13
  DESCRIBE YOUR GEM HERE
8
14
 
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -1,7 +1,8 @@
1
- #!/usr/bin/env ruby -w
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  require 'optparse'
4
4
  require 'methadone'
5
+ require '<%= gemname %>'
5
6
 
6
7
  include Methadone::Main
7
8
 
@@ -32,4 +33,6 @@ end
32
33
  # # Make an argument optional
33
34
  # arg :optional_arg, :optional
34
35
 
36
+ version <%= module_name %>::VERSION
37
+
35
38
  go!
File without changes
@@ -7,5 +7,7 @@ Feature: My bootstrapped app kinda works
7
7
  When I get help for "<%= gemname %>"
8
8
  Then the exit status should be 0
9
9
  And the banner should be present
10
- And the banner should document that this app takes no options
10
+ And the banner should document that this app takes options
11
+ And the following options should be documented:
12
+ |--version|
11
13
  And the banner should document that this app takes no arguments
@@ -0,0 +1,7 @@
1
+ Copyright (c) <%= Time.now.year %> YOUR NAME
2
+
3
+ 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:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ 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.
@@ -9,6 +9,8 @@ class TestMain < BaseTest
9
9
  @logged = []
10
10
  @original_argv = ARGV.clone
11
11
  ARGV.clear
12
+ @old_stdout = $stdout
13
+ $stdout = StringIO.new
12
14
  end
13
15
 
14
16
  # Override error so we can capture what's being logged at this level
@@ -18,6 +20,8 @@ class TestMain < BaseTest
18
20
 
19
21
  def teardown
20
22
  set_argv @original_argv
23
+ ENV.delete('DEBUG')
24
+ $stdout = @old_stdout
21
25
  end
22
26
 
23
27
  test_that "my main block gets called by run and has access to CLILogging" do
@@ -118,6 +122,20 @@ class TestMain < BaseTest
118
122
  }
119
123
  end
120
124
 
125
+ test_that "go allows the exception raised to leak through if DEBUG is set in the environment" do
126
+ Given {
127
+ ENV['DEBUG'] = 'true'
128
+ main do
129
+ raise ArgumentError,"oh noes"
130
+ end
131
+ }
132
+ Then {
133
+ assert_raises ArgumentError do
134
+ When run_go!
135
+ end
136
+ }
137
+ end
138
+
121
139
  test_that "An exception that's not a StandardError causes the excepteion to break through and raise" do
122
140
  Given {
123
141
  main do
@@ -159,6 +177,20 @@ class TestMain < BaseTest
159
177
  }
160
178
  end
161
179
 
180
+ test_that "go allows the special methadone exception to leak through if DEBUG is set in the environment" do
181
+ Given {
182
+ ENV['DEBUG'] = 'true'
183
+ main do
184
+ raise Methadone::Error.new(4,"oh noes")
185
+ end
186
+ }
187
+ Then {
188
+ assert_raises Methadone::Error do
189
+ When run_go!
190
+ end
191
+ }
192
+ end
193
+
162
194
  test_that "can exit with a specific status by using the helper method instead of making a new exception" do
163
195
  Given {
164
196
  main do
@@ -194,7 +226,7 @@ class TestMain < BaseTest
194
226
  }
195
227
  end
196
228
 
197
- test_that "when the command line is invalid, we exit with 64" do
229
+ test_that "when the command line is invalid, we exit with 64 and print the CLI help" do
198
230
  Given {
199
231
  main do
200
232
  end
@@ -207,6 +239,27 @@ class TestMain < BaseTest
207
239
 
208
240
  Then {
209
241
  assert_exits(64) { When run_go! }
242
+ assert $stdout.string.include?(opts.to_s),"Expected #{$stdout.string} to contain #{opts.to_s}"
243
+ }
244
+ end
245
+
246
+ test_that "when setting defualts they get copied to strings/symbols as well" do
247
+ Given {
248
+ @flag_with_string_key_defalt = nil
249
+ @flag_with_symbol_key_defalt = nil
250
+ main do
251
+ @flag_with_string_key_defalt = options[:foo]
252
+ @flag_with_symbol_key_defalt = options['bar']
253
+ end
254
+ options['foo'] = 'FOO'
255
+ options[:bar] = 'BAR'
256
+ on("--foo")
257
+ on("--bar")
258
+ }
259
+ When run_go_safely
260
+ Then {
261
+ assert_equal 'FOO',@flag_with_string_key_defalt
262
+ assert_equal 'BAR',@flag_with_symbol_key_defalt
210
263
  }
211
264
  end
212
265
 
@@ -379,6 +432,42 @@ class TestMain < BaseTest
379
432
  }
380
433
  end
381
434
 
435
+ test_that "when I specify a version, it shows up in the banner" do
436
+ Given {
437
+ main{}
438
+ version "0.0.1"
439
+ }
440
+
441
+ Then {
442
+ opts.banner.should match /^v0.0.1/m
443
+ }
444
+ end
445
+
446
+ test_that "when I specify a version, I can get help via --version" do
447
+ Given {
448
+ main{}
449
+ version "0.0.1"
450
+ set_argv(['--verison'])
451
+ }
452
+ Then run_go_safely
453
+ And {
454
+ opts.to_s.should match /Show help\/version info/m
455
+ }
456
+ end
457
+
458
+ test_that "when I specify a version with custom help, it shows up" do
459
+ @version_message = "SHOW ME VERSIONS"
460
+ Given {
461
+ main{}
462
+ version "0.0.1",@version_message
463
+ set_argv(['--verison'])
464
+ }
465
+ Then run_go_safely
466
+ And {
467
+ opts.to_s.should match /#{@version_message}/
468
+ }
469
+ end
470
+
382
471
  private
383
472
 
384
473
  def main_shouldve_been_called
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: methadone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-10 00:00:00.000000000Z
12
+ date: 2011-12-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70257700838920 !ruby/object:Gem::Requirement
16
+ requirement: &70122152989000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70257700838920
24
+ version_requirements: *70122152989000
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec-expectations
27
- requirement: &70257700838400 !ruby/object:Gem::Requirement
27
+ requirement: &70122152988360 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '2.6'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70257700838400
35
+ version_requirements: *70122152988360
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70257700837880 !ruby/object:Gem::Requirement
38
+ requirement: &70122152987860 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70257700837880
46
+ version_requirements: *70122152987860
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &70257700837200 !ruby/object:Gem::Requirement
49
+ requirement: &70122152987240 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '3.9'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70257700837200
57
+ version_requirements: *70122152987240
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: cucumber
60
- requirement: &70257700836640 !ruby/object:Gem::Requirement
60
+ requirement: &70122152986640 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.1.1
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70257700836640
68
+ version_requirements: *70122152986640
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: aruba
71
- requirement: &70257700836160 !ruby/object:Gem::Requirement
71
+ requirement: &70122152986180 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70257700836160
79
+ version_requirements: *70122152986180
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: simplecov
82
- requirement: &70257700835560 !ruby/object:Gem::Requirement
82
+ requirement: &70122152985620 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0.5'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70257700835560
90
+ version_requirements: *70122152985620
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: test_unit-given
93
- requirement: &70257700834960 !ruby/object:Gem::Requirement
93
+ requirement: &70122152985020 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: 0.1.1
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70257700834960
101
+ version_requirements: *70122152985020
102
102
  description: Methadone provides a lot of small but useful features for developing
103
103
  a command-line app, including an opinionated bootstrapping process, some helpful
104
104
  cucumber steps, and some classes to bridge logging and output into a simple, unified,
@@ -112,6 +112,7 @@ extra_rdoc_files: []
112
112
  files:
113
113
  - .gitignore
114
114
  - .rvmrc
115
+ - .travis.yml
115
116
  - Gemfile
116
117
  - LICENSE.txt
117
118
  - README.rdoc
@@ -121,8 +122,11 @@ files:
121
122
  - features/license.feature
122
123
  - features/readme.feature
123
124
  - features/step_definitions/bootstrap_steps.rb
125
+ - features/step_definitions/license_steps.rb
124
126
  - features/step_definitions/readme_steps.rb
127
+ - features/step_definitions/version_steps.rb
125
128
  - features/support/env.rb
129
+ - features/version.feature
126
130
  - lib/methadone.rb
127
131
  - lib/methadone/cli.rb
128
132
  - lib/methadone/cli_logger.rb
@@ -135,10 +139,13 @@ files:
135
139
  - templates/full/.gitignore.erb
136
140
  - templates/full/README.rdoc.erb
137
141
  - templates/full/Rakefile.erb
142
+ - templates/full/apache_LICENSE.txt.erb
138
143
  - templates/full/bin/executable.erb
144
+ - templates/full/custom_LICENSE.txt.erb
139
145
  - templates/full/features/executable.feature.erb
140
146
  - templates/full/features/step_definitions/executable_steps.rb.erb
141
147
  - templates/full/features/support/env.rb.erb
148
+ - templates/full/mit_LICENSE.txt.erb
142
149
  - templates/full/test/tc_something.rb.erb
143
150
  - test/base_test.rb
144
151
  - test/test_cli_logger.rb
@@ -173,8 +180,11 @@ test_files:
173
180
  - features/license.feature
174
181
  - features/readme.feature
175
182
  - features/step_definitions/bootstrap_steps.rb
183
+ - features/step_definitions/license_steps.rb
176
184
  - features/step_definitions/readme_steps.rb
185
+ - features/step_definitions/version_steps.rb
177
186
  - features/support/env.rb
187
+ - features/version.feature
178
188
  - test/base_test.rb
179
189
  - test/test_cli_logger.rb
180
190
  - test/test_cli_logging.rb