methadone 0.4.1 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/methadone CHANGED
@@ -32,9 +32,13 @@ main do |app_name|
32
32
 
33
33
  license = options[:license]
34
34
  if license
35
- copy_file "#{options[:license]}_LICENSE.txt", :as => "LICENSE.txt"
35
+ if license == 'NONE'
36
+ license = nil
37
+ else
38
+ copy_file "#{options[:license]}_LICENSE.txt", :as => "LICENSE.txt"
39
+ end
36
40
  else
37
- warn "your app has no license"
41
+ warn "warning: your app has no license"
38
42
  end
39
43
 
40
44
 
@@ -61,7 +65,7 @@ description "Kick the bash habit by bootstrapping your Ruby command-line apps"
61
65
  on("--force","Overwrite files if they exist")
62
66
  on("--[no-]readme","[Do not ]produce a README file")
63
67
 
64
- licenses = %w(mit apache custom)
68
+ licenses = %w(mit apache custom NONE)
65
69
  on("-l LICENSE","--license",licenses,"Specify the license for your project (#{licenses.join('|')})")
66
70
 
67
71
  arg :app_name, :required
@@ -28,5 +28,10 @@ Feature: Users should get the license included
28
28
 
29
29
  Scenario: No license specified
30
30
  When I successfully run `methadone tmp/newgem`
31
- Then the stderr should contain "your app has no license"
31
+ Then the stderr should contain "warning: your app has no license"
32
+ And the README should not reference a license
33
+
34
+ Scenario: No license specified explicitly
35
+ When I successfully run `methadone -l NONE tmp/newgem`
36
+ Then the stderr should not contain "warning: your app has no license"
32
37
  And the README should not reference a license
@@ -30,14 +30,21 @@ module Methadone
30
30
  end
31
31
 
32
32
  # Change the global logger that includers will use. Useful if you
33
- # don't want the default configured logger.
33
+ # don't want the default configured logger. Note that the +change_logger+
34
+ # version is preferred because Ruby will often parse <tt>logger = Logger.new</tt> as
35
+ # the declaration of, and assignment to, of a local variable. You'd need to
36
+ # do <tt>self.logger=Logger.new</tt> to be sure. This method
37
+ # is a bit easier.
34
38
  #
35
39
  # +new_logger+:: the new logger. May not be nil and should be a logger of some kind
36
- def logger=(new_logger)
40
+ def change_logger(new_logger)
37
41
  raise ArgumentError,"Logger may not be nil" if new_logger.nil?
38
42
  @@logger = new_logger
39
43
  end
40
44
 
45
+ alias logger= change_logger
46
+
47
+
41
48
  # pass-through to <tt>logger.debug(progname,&block)</tt>
42
49
  def debug(progname = nil, &block); logger.debug(progname,&block); end
43
50
  # pass-through to <tt>logger.info(progname,&block)</tt>
@@ -195,7 +195,23 @@ module Methadone
195
195
  end
196
196
 
197
197
  # Returns a Hash that you can use to store or retrieve options
198
- # parsed from the command line
198
+ # parsed from the command line. When you put values in here, if you do so
199
+ # *before* you've declared your command-line interface via #on, the value
200
+ # will be used in the docstring to indicate it is the default.
201
+ #
202
+ # Example
203
+ #
204
+ # main do
205
+ # puts options[:foo] # put the value of --foo that the user provided
206
+ # end
207
+ #
208
+ # options[:foo] = "bar" # set "bar" as the default value for --foo, which
209
+ # # will cause us to include "(default: bar)" in the
210
+ # # docstring
211
+ #
212
+ # on("--foo FOO","Sets the foo")
213
+ # go!
214
+ #
199
215
  def options
200
216
  @options
201
217
  end
@@ -291,6 +307,7 @@ module Methadone
291
307
  # for how that works.
292
308
  def on(*args,&block)
293
309
  @accept_options = true
310
+ args = add_default_value_to_docstring(*args)
294
311
  if block
295
312
  @option_parser.on(*args,&block)
296
313
  else
@@ -345,6 +362,22 @@ module Methadone
345
362
 
346
363
  private
347
364
 
365
+ def add_default_value_to_docstring(*args)
366
+ default_value = nil
367
+ option_names_from(args).each do |option|
368
+ default_value = (@options[option.to_s] || @options[option.to_sym]) if default_value.nil?
369
+ end
370
+ if default_value.nil?
371
+ args
372
+ else
373
+ args + ["(default: #{default_value})"]
374
+ end
375
+ end
376
+
377
+ def option_names_from(args)
378
+ args.select { |_| _ =~ /^\-/ }.map { |_| _.gsub(/^\-+/,'').gsub(/\s.*$/,'') }
379
+ end
380
+
348
381
  def set_banner
349
382
  unless @user_specified_banner
350
383
  new_banner="Usage: #{::File.basename($0)}"
@@ -1,3 +1,3 @@
1
1
  module Methadone
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.1"
3
3
  end
data/methadone.gemspec CHANGED
@@ -25,5 +25,5 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency("cucumber","~> 1.1.1")
26
26
  s.add_development_dependency("aruba")
27
27
  s.add_development_dependency("simplecov", "~> 0.5")
28
- s.add_development_dependency("test_unit-given", ">= 0.1.1")
28
+ s.add_development_dependency("clean_test", "~> 0.10")
29
29
  end
data/test/base_test.rb CHANGED
@@ -4,24 +4,7 @@ SimpleCov.start do
4
4
  end
5
5
  require 'test/unit'
6
6
  require 'rspec/expectations'
7
- require 'test/unit/given'
7
+ require 'clean_test/test_case'
8
8
 
9
- class BaseTest < Test::Unit::Given::TestCase
10
- # Copied from Rails; makes a test method using a string
11
- def self.test(name, &block)
12
- test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
13
- defined = instance_method(test_name) rescue false
14
- raise "#{test_name} is already defined in #{self}" if defined
15
- if block_given?
16
- define_method(test_name, &block)
17
- else
18
- define_method(test_name) do
19
- raise "No implementation provided for #{name}"
20
- end
21
- end
22
- end
23
-
24
- def test_nothing
25
- # Seems 1.8 wants to have a test here?
26
- end
9
+ class BaseTest < Clean::Test::TestCase
27
10
  end
@@ -45,14 +45,33 @@ class TestCLILogging < BaseTest
45
45
  }
46
46
  end
47
47
 
48
- test_that "we can change the global logger" do
48
+ test_that "we can change the global logger via self." do
49
49
  Given {
50
50
  @first = MyClassThatLogsToStdout.new
51
51
  @second = MyOtherClassThatLogsToStdout.new
52
52
  @logger_id = @second.logger_id
53
53
  }
54
54
  When {
55
- @second.change_logger
55
+ @second.instance_eval do
56
+ self.logger=(Methadone::CLILogger.new)
57
+ end
58
+ }
59
+ Then {
60
+ @logger_id.should_not == @second.logger_id
61
+ @first.logger_id.should == @second.logger_id
62
+ }
63
+ end
64
+
65
+ test_that "we can change the global logger change_logger()" do
66
+ Given {
67
+ @first = MyClassThatLogsToStdout.new
68
+ @second = MyOtherClassThatLogsToStdout.new
69
+ @logger_id = @second.logger_id
70
+ }
71
+ When {
72
+ @second.instance_eval do
73
+ change_logger(Logger.new(STDERR))
74
+ end
56
75
  }
57
76
  Then {
58
77
  @logger_id.should_not == @second.logger_id
@@ -65,7 +84,11 @@ class TestCLILogging < BaseTest
65
84
  @other_class = MyOtherClassThatLogsToStdout.new
66
85
  }
67
86
  Then {
68
- lambda { MyOtherClassThatLogsToStdout.new.change_to_nil_logger }.should raise_error(ArgumentError)
87
+ lambda {
88
+ MyOtherClassThatLogsToStdout.new.instance_eval do
89
+ self.logger=(nil)
90
+ end
91
+ }.should raise_error(ArgumentError)
69
92
  }
70
93
  end
71
94
 
@@ -108,14 +131,6 @@ class TestCLILogging < BaseTest
108
131
  fatal("fatal")
109
132
  end
110
133
 
111
- def change_logger
112
- self.logger=Methadone::CLILogger.new
113
- end
114
-
115
- def change_to_nil_logger
116
- self.logger = nil
117
- end
118
-
119
134
  def logger_id; logger.object_id; end
120
135
  end
121
136
  end
data/test/test_main.rb CHANGED
@@ -468,6 +468,35 @@ class TestMain < BaseTest
468
468
  }
469
469
  end
470
470
 
471
+ test_that "default values for options are put into the docstring" do
472
+ Given {
473
+ main {}
474
+ options[:foo] = "bar"
475
+ on("--foo ARG","Indicate the type of foo")
476
+ }
477
+ When {
478
+ @help_string = opts.to_s
479
+ }
480
+ When {
481
+ @help_string.should match /\(default: bar\)/
482
+ }
483
+
484
+ end
485
+
486
+ test_that "default values for options with several names are put into the docstring" do
487
+ Given {
488
+ main {}
489
+ options[:foo] = "bar"
490
+ on("-f ARG","--foo","Indicate the type of foo")
491
+ }
492
+ When {
493
+ @help_string = opts.to_s
494
+ }
495
+ When {
496
+ @help_string.should match /\(default: bar\)/
497
+ }
498
+ end
499
+
471
500
  private
472
501
 
473
502
  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.4.1
4
+ version: 0.5.1
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: 2012-01-11 00:00:00.000000000Z
12
+ date: 2012-01-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70174171756980 !ruby/object:Gem::Requirement
16
+ requirement: &70157645151840 !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: *70174171756980
24
+ version_requirements: *70157645151840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec-expectations
27
- requirement: &70174171756480 !ruby/object:Gem::Requirement
27
+ requirement: &70157645151280 !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: *70174171756480
35
+ version_requirements: *70157645151280
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70174171756060 !ruby/object:Gem::Requirement
38
+ requirement: &70157645150780 !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: *70174171756060
46
+ version_requirements: *70157645150780
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &70174171755460 !ruby/object:Gem::Requirement
49
+ requirement: &70157645150160 !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: *70174171755460
57
+ version_requirements: *70157645150160
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: cucumber
60
- requirement: &70174171748260 !ruby/object:Gem::Requirement
60
+ requirement: &70157645149420 !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: *70174171748260
68
+ version_requirements: *70157645149420
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: aruba
71
- requirement: &70174171747880 !ruby/object:Gem::Requirement
71
+ requirement: &70157645143000 !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: *70174171747880
79
+ version_requirements: *70157645143000
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: simplecov
82
- requirement: &70174171747340 !ruby/object:Gem::Requirement
82
+ requirement: &70157645142460 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,18 +87,18 @@ dependencies:
87
87
  version: '0.5'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70174171747340
90
+ version_requirements: *70157645142460
91
91
  - !ruby/object:Gem::Dependency
92
- name: test_unit-given
93
- requirement: &70174171746840 !ruby/object:Gem::Requirement
92
+ name: clean_test
93
+ requirement: &70157645141960 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
- - - ! '>='
96
+ - - ~>
97
97
  - !ruby/object:Gem::Version
98
- version: 0.1.1
98
+ version: '0.10'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70174171746840
101
+ version_requirements: *70157645141960
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,