cooloptions 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,4 +1,10 @@
1
- == 1.0.5 /
1
+ == 1.1.0 / 2007-01-10
2
+
3
+ * Incremented the version number to more rationally reflect the addition of
4
+ CoolOptions#desc in 1.0.5.
5
+ * Fixed handling of overlapping automatic short options.
6
+
7
+ == 1.0.5 / 2006-12-09
2
8
 
3
9
  * Added CoolOptions#desc (suggested by John Long).
4
10
 
data/lib/cooloptions.rb CHANGED
@@ -11,7 +11,7 @@ require 'ostruct'
11
11
  # :include:samples/literate.rb
12
12
 
13
13
  class CoolOptions
14
- VERSION = '1.0.5' #:nodoc:
14
+ VERSION = '1.1.0' #:nodoc:
15
15
 
16
16
  class Error < StandardError #:nodoc:
17
17
  end
@@ -51,6 +51,7 @@ class CoolOptions
51
51
  @required = []
52
52
  @result = {}
53
53
  @after = nil
54
+ @used_shorts = {}
54
55
  end
55
56
 
56
57
  # Adds additional descriptive text to the help text.
@@ -80,7 +81,10 @@ class CoolOptions
80
81
  long = "[no-]#{long}"
81
82
  end
82
83
 
83
- args = ["-#{short}", "--#{long}", description]
84
+ args = []
85
+ args << "-#{short}" unless @used_shorts[short]
86
+ @used_shorts[short] = true
87
+ args.concat(["--#{long}", description])
84
88
  if default == NO_DEFAULT
85
89
  @required << key
86
90
  else
@@ -129,4 +129,32 @@ EOH
129
129
  end
130
130
  assert called
131
131
  end
132
+
133
+ def test_should_not_assign_already_used_short_options
134
+ begin
135
+ CoolOptions.parse!('details', %w(--help)) do |o|
136
+ o.on 'cl C', 'cl'
137
+ o.on 'ca', 'ca'
138
+ end
139
+ rescue SystemExit
140
+ rescued = true
141
+ end
142
+
143
+ assert rescued
144
+ assert_equal <<EOH, @out.string
145
+ Usage: #{File.basename($0)} details
146
+ -c, --cl C cl
147
+ --[no-]ca ca
148
+ -h, --help This help info.
149
+ EOH
150
+ end
151
+
152
+ def test_should_handle_overlapping_short_options
153
+ r = parse!(%w(-c d)) do |o|
154
+ o.on 'cl C', 'cl'
155
+ o.on 'ca', 'ca', false
156
+ end
157
+
158
+ assert 'd', r.cl
159
+ end
132
160
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: cooloptions
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.5
7
- date: 2006-12-09 00:00:00 -05:00
6
+ version: 1.1.0
7
+ date: 2007-01-10 00:00:00 -05:00
8
8
  summary: CoolOptions is a simple wrapper around optparse that provides less configuration and more convenience for doing command-line option handling.
9
9
  require_paths:
10
10
  - lib