acclaim 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,10 +2,7 @@ source :rubygems
2
2
 
3
3
  gemspec
4
4
 
5
- {
6
- ribbon: '~/projects/ribbon',
7
- rookie: '~/projects/rookie'
8
- }.each do |project, path|
5
+ { ribbon: '~/projects/ribbon', rookie: '~/projects/rookie' }.each do |project, path|
9
6
  path = File.expand_path path
10
7
  gem project.to_s, path: path if Dir.exists? path
11
8
  end
data/LICENSE.MPL2 ADDED
@@ -0,0 +1,3 @@
1
+ This Source Code Form is subject to the terms of the Mozilla Public
2
+ License, v. 2.0. If a copy of the MPL was not distributed with this file,
3
+ You can obtain one at http://mozilla.org/MPL/2.0/.
data/acclaim.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new('acclaim') do |gem|
14
14
  gem.author = 'Matheus Afonso Martins Moreira'
15
15
  gem.email = 'matheus.a.m.moreira@gmail.com'
16
16
 
17
- gem.files = `git ls-files`.split "\n"
17
+ gem.files = `git ls-files`.split "\n"
18
18
 
19
19
  gem.add_runtime_dependency 'ribbon'
20
20
 
data/lib/acclaim.rb CHANGED
@@ -2,10 +2,6 @@
2
2
  module Acclaim
3
3
  end
4
4
 
5
- %w(
6
-
7
- command
8
- option
9
- version
10
-
11
- ).each { |file| require file.prepend 'acclaim/' }
5
+ %w(command option version).each do |file|
6
+ require file.prepend 'acclaim/'
7
+ end
@@ -70,7 +70,7 @@ module Acclaim
70
70
  end
71
71
 
72
72
  # Same as #option.
73
- alias :opt :option
73
+ alias opt option
74
74
 
75
75
  # The block which is executed when this command is called. It is given 2
76
76
  # parameters; the first is an Ribbon instance which can be queried for
@@ -80,7 +80,7 @@ module Acclaim
80
80
  end
81
81
 
82
82
  # Same as #action.
83
- alias :when_called :action
83
+ alias when_called action
84
84
 
85
85
  # Adds help subcommand and options to this command.
86
86
  def help(*args)
@@ -135,7 +135,7 @@ module Acclaim
135
135
  end
136
136
 
137
137
  # Same as #execute.
138
- alias :call :execute
138
+ alias call execute
139
139
 
140
140
  # True if this is a top-level command.
141
141
  def root?
@@ -7,7 +7,6 @@ module Acclaim
7
7
  # Module which adds help support to a command.
8
8
  module Help
9
9
 
10
- # The class methods.
11
10
  class << self
12
11
 
13
12
  # Creates a help subcommand that inherits from the given +base+ command
@@ -63,8 +62,8 @@ module Acclaim
63
62
  # [:switches] The switches used when creating the help option.
64
63
  def add_options_to!(*args)
65
64
  opts, command = args.extract_ribbon!, args.shift
66
- switches = opts.switches? %w(-h --help)
67
- description = opts.description? 'Show usage information and exit.'
65
+ switches = opts.switches? { %w(-h --help) }
66
+ description = opts.description? { 'Show usage information and exit.' }
68
67
  command.option :acclaim_help, *switches, description
69
68
  end
70
69
 
@@ -8,7 +8,6 @@ module Acclaim
8
8
  # Manages help templates.
9
9
  module Template
10
10
 
11
- # The class methods.
12
11
  class << self
13
12
 
14
13
  # Returns the +template+ folder relative to this directory.
@@ -6,7 +6,6 @@ module Acclaim
6
6
  # Module which adds version query support to a command.
7
7
  module Version
8
8
 
9
- # The class methods.
10
9
  class << self
11
10
 
12
11
  # Creates a <tt>version</tt> subcommand that inherits from the given
@@ -43,8 +42,8 @@ module Acclaim
43
42
  # [:switches] The switches used when creating the version option.
44
43
  def add_options_to!(*args)
45
44
  opts, command = args.extract_ribbon!, args.shift
46
- switches = opts.switches? %w(-v --version)
47
- description = opts.description? 'Show version and exit.'
45
+ switches = opts.switches? { %w(-v --version) }
46
+ description = opts.description? { 'Show version and exit.' }
48
47
  command.option :acclaim_version, *switches, description
49
48
  end
50
49
 
@@ -128,19 +128,18 @@ module Acclaim
128
128
 
129
129
  # Returns +true+ if this option takes no arguments.
130
130
  def flag?
131
- not arity or arity == [0, 0]
131
+ arity and arity.none?
132
132
  end
133
133
 
134
134
  # Same as <tt>flag?</tt>
135
- alias :bool? :flag?
135
+ alias bool? flag?
136
136
 
137
137
  # Same as <tt>flag?</tt>
138
- alias :boolean? :flag?
138
+ alias boolean? flag?
139
139
 
140
140
  # Same as <tt>flag?</tt>
141
- alias :switch? :flag?
141
+ alias switch? flag?
142
142
 
143
- # The class methods.
144
143
  class << self
145
144
 
146
145
  # Derives a name from the given key's string representation. All
@@ -150,7 +149,7 @@ module Acclaim
150
149
  # resulting name is not a valid switch, a +NameError+ will be raised.
151
150
  def name_from(key)
152
151
  name = key.to_s
153
- raise ArgumentError, "Can't derive name from empty string representation." if name.empty?
152
+ raise ArgumentError, "Can't derive name from empty key." if name.empty?
154
153
  name = (name.length == 1 ? '-' : '--') + name
155
154
  name.gsub! '_', '-'
156
155
  raise NameError, "Derived name is invalid: #{name}" unless name =~ Parser::Regexp::SWITCH
@@ -12,7 +12,7 @@ module Acclaim
12
12
  attr_accessor :optional
13
13
 
14
14
  # Same as +minimum+.
15
- alias :required :minimum
15
+ alias required minimum
16
16
 
17
17
  # Initializes this arity with a number of required parameters and a number
18
18
  # of optional parameters. If the latter is less than zero, then it means
@@ -27,6 +27,11 @@ module Acclaim
27
27
  optional.zero? and minimum == n
28
28
  end
29
29
 
30
+ # Returns +true+ if the option takes no parameters.
31
+ def none?
32
+ only? 0
33
+ end
34
+
30
35
  # Returns +true+ if the option can take an infinite number of arguments.
31
36
  def unlimited?
32
37
  optional < 0
@@ -52,10 +57,10 @@ module Acclaim
52
57
  end
53
58
 
54
59
  # Same as +to_a+.
55
- alias :to_ary :to_a
60
+ alias to_ary to_a
56
61
 
57
62
  # Same as +to_a+.
58
- alias :to_array :to_a
63
+ alias to_array to_a
59
64
 
60
65
  # Equivalent to <tt>to_a.hash</tt>.
61
66
  def hash
@@ -72,10 +77,10 @@ module Acclaim
72
77
  end
73
78
 
74
79
  # Same as <tt>==</tt>
75
- alias :eql? :==
80
+ alias eql? ==
76
81
 
77
82
  # Same as <tt>==</tt>
78
- alias :=== :==
83
+ alias === ==
79
84
 
80
85
  # Returns a string in the following format:
81
86
  #
@@ -1,3 +1,4 @@
1
+ require 'acclaim/option/parser/error'
1
2
  require 'acclaim/option/parser/regexp'
2
3
  require 'ribbon'
3
4
 
@@ -9,34 +10,6 @@ module Acclaim
9
10
 
10
11
  include Parser::Regexp
11
12
 
12
- # Errors raised by the parser.
13
- class Error < StandardError
14
-
15
- # Raises an Error with the following error message:
16
- #
17
- # Wrong number of arguments (#{actual} for #{minimum})
18
- def self.raise_wrong_arg_number(actual, minimum, optional)
19
- raise self, "Wrong number of arguments (#{actual} for #{minimum})"
20
- end
21
-
22
- # Raises an Error with the following error message:
23
- #
24
- # Missing required argument (#{option.names.join '|'})
25
- def self.raise_missing_required(option)
26
- names = option.names.join '|'
27
- raise self, "Missing required argument (#{names})"
28
- end
29
-
30
- # Raises an error with the following error message:
31
- #
32
- # Multiple instances of [#{options.names.join ''}] encountered
33
- def self.raise_multiple(option)
34
- names = option.names.join '|'
35
- raise self, "Multiple instances of [#{names}] encountered"
36
- end
37
-
38
- end
39
-
40
13
  # The argument array to parse.
41
14
  attr_accessor :argv
42
15
 
@@ -0,0 +1,35 @@
1
+ module Acclaim
2
+ class Option
3
+ class Parser
4
+
5
+ # Errors raised by the parser.
6
+ class Error < StandardError
7
+
8
+ # Raises an Error with the following error message:
9
+ #
10
+ # Wrong number of arguments (#{actual} for #{minimum})
11
+ def self.raise_wrong_arg_number(actual, minimum, optional)
12
+ raise self, "Wrong number of arguments (#{actual} for #{minimum})"
13
+ end
14
+
15
+ # Raises an Error with the following error message:
16
+ #
17
+ # Missing required argument (#{option.names.join '|'})
18
+ def self.raise_missing_required(option)
19
+ names = option.names.join '|'
20
+ raise self, "Missing required argument (#{names})"
21
+ end
22
+
23
+ # Raises an error with the following error message:
24
+ #
25
+ # Multiple instances of [#{options.names.join ''}] encountered
26
+ def self.raise_multiple(option)
27
+ names = option.names.join '|'
28
+ raise self, "Multiple instances of [#{names}] encountered"
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -12,6 +12,8 @@ module Acclaim
12
12
  # <tt>'-mult'</tt> should match MULTIPLE_SHORT_SWITCHES, and will be
13
13
  # split into <tt>%w(-m -u -l -t)</tt>, which in turn should match this
14
14
  # regular expression.
15
+ #
16
+ # \w is not used because it matches digits.
15
17
  SHORT_SWITCH = /\A-[a-zA-Z_]\Z/.freeze
16
18
 
17
19
  # Regular expression for a long option switch.
@@ -24,6 +26,8 @@ module Acclaim
24
26
  # switch.
25
27
  #
26
28
  # Examples: <tt>-xvf; -abc; -de_f</tt>
29
+ #
30
+ # \w is not used because it matches digits.
27
31
  MULTIPLE_SHORT_SWITCHES = /\A-[a-zA-Z_]{2,}\Z/.freeze
28
32
 
29
33
  # Regular expression for a long switch connected to its parameters with
@@ -59,9 +59,6 @@ module Acclaim
59
59
  end
60
60
  end
61
61
 
62
- require 'acclaim/option/type/date'
63
- require 'acclaim/option/type/date_time'
64
- require 'acclaim/option/type/string'
65
- require 'acclaim/option/type/symbol'
66
- require 'acclaim/option/type/time'
67
- require 'acclaim/option/type/uri'
62
+ %w(date date_time string symbol time uri).each do |type|
63
+ require type.prepend 'acclaim/option/type/'
64
+ end
@@ -16,7 +16,7 @@ module Acclaim
16
16
  # Patch version.
17
17
  #
18
18
  # Increments denote changes in implementation.
19
- PATCH = 2
19
+ PATCH = 3
20
20
 
21
21
  # Build version.
22
22
  #
@@ -24,6 +24,12 @@ describe Acclaim::Option::Arity do
24
24
  end
25
25
  end
26
26
 
27
+ describe '#none?' do
28
+ it 'should return true' do
29
+ subject.none?.should be_true
30
+ end
31
+ end
32
+
27
33
  describe '#unlimited?' do
28
34
  it 'should return false' do
29
35
  subject.unlimited?.should be_false
@@ -61,6 +67,12 @@ describe Acclaim::Option::Arity do
61
67
  end
62
68
  end
63
69
 
70
+ describe '#none?' do
71
+ it 'should return false' do
72
+ subject.none?.should be_false
73
+ end
74
+ end
75
+
64
76
  describe '#unlimited?' do
65
77
  it 'should return false' do
66
78
  subject.unlimited?.should be_false
@@ -99,6 +111,12 @@ describe Acclaim::Option::Arity do
99
111
  end
100
112
  end
101
113
 
114
+ describe '#none?' do
115
+ it 'should return false' do
116
+ subject.none?.should be_false
117
+ end
118
+ end
119
+
102
120
  describe '#unlimited?' do
103
121
  it 'should return true' do
104
122
  subject.unlimited?.should be_true
@@ -138,6 +156,12 @@ describe Acclaim::Option::Arity do
138
156
  end
139
157
  end
140
158
 
159
+ describe '#none?' do
160
+ it 'should return false' do
161
+ subject.none?.should be_false
162
+ end
163
+ end
164
+
141
165
  describe '#unlimited?' do
142
166
  it 'should return false' do
143
167
  subject.unlimited?.should be_false
@@ -175,6 +199,12 @@ describe Acclaim::Option::Arity do
175
199
  end
176
200
  end
177
201
 
202
+ describe '#none?' do
203
+ it 'should return false' do
204
+ subject.none?.should be_false
205
+ end
206
+ end
207
+
178
208
  describe '#unlimited?' do
179
209
  it 'should return false' do
180
210
  subject.unlimited?.should be_false
@@ -213,6 +243,12 @@ describe Acclaim::Option::Arity do
213
243
  end
214
244
  end
215
245
 
246
+ describe '#none?' do
247
+ it 'should return false' do
248
+ subject.none?.should be_false
249
+ end
250
+ end
251
+
216
252
  describe '#unlimited?' do
217
253
  it 'should return true' do
218
254
  subject.unlimited?.should be_true
@@ -18,7 +18,7 @@ describe Acclaim::Option do
18
18
  context 'when given multiple strings' do
19
19
  let(:switches) { %w(-s --switch) }
20
20
  let(:description) { 'Description' }
21
- let(:args) { [switches, description].flatten! }
21
+ let(:args) { [*switches, description] }
22
22
 
23
23
  it 'should find the switches' do
24
24
  subject.names.should == switches
@@ -126,7 +126,7 @@ describe Acclaim::Option do
126
126
  let(:block) { proc { |*args| p args } }
127
127
 
128
128
  it 'should have a custom handler' do
129
- subject.handler.should be_a(Proc)
129
+ subject.handler.should respond_to(:call)
130
130
  end
131
131
  end
132
132
  end
@@ -140,7 +140,7 @@ describe Acclaim::Option do
140
140
  let!(:params) { %w(a b c d) }
141
141
 
142
142
  it 'should convert the parameters to strings' do
143
- converted.should == params.map(&:to_s)
143
+ converted.should == params
144
144
  end
145
145
  end
146
146
 
@@ -149,7 +149,7 @@ describe Acclaim::Option do
149
149
  let(:params) { %w(a b c d) }
150
150
 
151
151
  it 'should convert the parameters to strings' do
152
- converted.should == params.map(&:to_s)
152
+ converted.should == params
153
153
  end
154
154
  end
155
155
 
@@ -157,7 +157,7 @@ describe Acclaim::Option do
157
157
  let(:type) { Symbol }
158
158
  let(:params) { %w(a b c d) }
159
159
 
160
- it 'should convert the parameters to strings' do
160
+ it 'should convert the parameters to symbols' do
161
161
  converted.should == params.map(&:to_sym)
162
162
  end
163
163
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acclaim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
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-20 00:00:00.000000000 Z
12
+ date: 2012-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ribbon
16
- requirement: &11055320 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *11055320
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rspec
27
- requirement: &11054640 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *11054640
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rookie
38
- requirement: &11053820 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *11053820
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  description: Command-line option parser and command interface.
48
63
  email: matheus.a.m.moreira@gmail.com
49
64
  executables: []
@@ -53,7 +68,7 @@ files:
53
68
  - .gitignore
54
69
  - .rvmrc
55
70
  - Gemfile
56
- - LICENSE.GPLv3
71
+ - LICENSE.MPL2
57
72
  - README.markdown
58
73
  - Rakefile
59
74
  - acclaim.gemspec
@@ -67,6 +82,7 @@ files:
67
82
  - lib/acclaim/option.rb
68
83
  - lib/acclaim/option/arity.rb
69
84
  - lib/acclaim/option/parser.rb
85
+ - lib/acclaim/option/parser/error.rb
70
86
  - lib/acclaim/option/parser/regexp.rb
71
87
  - lib/acclaim/option/type.rb
72
88
  - lib/acclaim/option/type/date.rb
@@ -95,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
111
  version: '0'
96
112
  segments:
97
113
  - 0
98
- hash: -2150306043143248332
114
+ hash: -3961771875420064857
99
115
  required_rubygems_version: !ruby/object:Gem::Requirement
100
116
  none: false
101
117
  requirements:
@@ -104,10 +120,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
120
  version: '0'
105
121
  segments:
106
122
  - 0
107
- hash: -2150306043143248332
123
+ hash: -3961771875420064857
108
124
  requirements: []
109
125
  rubyforge_project:
110
- rubygems_version: 1.8.10
126
+ rubygems_version: 1.8.21
111
127
  signing_key:
112
128
  specification_version: 3
113
129
  summary: Command-line option parser and command interface.
data/LICENSE.GPLv3 DELETED
@@ -1,14 +0,0 @@
1
- Copyright © 2011 Matheus Afonso Martins Moreira
2
-
3
- This program is free software: you can redistribute it and/or modify
4
- it under the terms of the GNU General Public License as published by
5
- the Free Software Foundation, either version 3 of the License, or
6
- (at your option) any later version.
7
-
8
- This program is distributed in the hope that it will be useful,
9
- but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- GNU General Public License for more details.
12
-
13
- You should have received a copy of the GNU General Public License
14
- along with this program. If not, see <http://www.gnu.org/licenses/>.