acclaim 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/acclaim/command.rb +18 -12
- data/lib/acclaim/version.rb +1 -1
- data/spec/acclaim/command_spec.rb +97 -2
- metadata +10 -10
data/lib/acclaim/command.rb
CHANGED
@@ -113,7 +113,7 @@ module Acclaim
|
|
113
113
|
# subcommands; if one is found, it will be invoked, if not, this command
|
114
114
|
# will be executed. A subcommand may be anywhere in the array as long as
|
115
115
|
# it is before an argument separator, which is tipically a double dash
|
116
|
-
# (<tt
|
116
|
+
# (<tt>--</tt>) and may be omitted.
|
117
117
|
#
|
118
118
|
# All argument separators will be deleted from the argument array before a
|
119
119
|
# command is executed.
|
@@ -157,35 +157,41 @@ module Acclaim
|
|
157
157
|
# until the root command.
|
158
158
|
alias until_root root
|
159
159
|
|
160
|
-
#
|
161
|
-
def
|
160
|
+
# Returns the sequence of commands from #root that leads to this command.
|
161
|
+
def path
|
162
162
|
Array.new.tap do |parents|
|
163
163
|
until_root do |command|
|
164
164
|
parents << command
|
165
165
|
end
|
166
|
+
parents.reverse!
|
166
167
|
end
|
167
168
|
end
|
168
169
|
|
170
|
+
# Return this command's parent commands.
|
171
|
+
def parents
|
172
|
+
path.tap { |path| path.pop; path.reverse! }
|
173
|
+
end
|
174
|
+
|
169
175
|
# Computes the full command line of this command, which takes parent
|
170
176
|
# commands into account.
|
171
177
|
#
|
172
178
|
# class Command < Acclaim::Command
|
173
|
-
# class
|
174
|
-
# class
|
179
|
+
# class Do < Command
|
180
|
+
# class Something < Do
|
175
181
|
# end
|
176
182
|
# end
|
177
183
|
# end
|
178
184
|
#
|
179
|
-
# Command::
|
180
|
-
# => "
|
185
|
+
# Command::Do::Something.full_line
|
186
|
+
# => "do something"
|
181
187
|
#
|
182
|
-
# Command::
|
183
|
-
# => "command
|
188
|
+
# Command::Do::Something.full_line include_root: true
|
189
|
+
# => "command do something"
|
184
190
|
def full_line(*args)
|
185
191
|
options = args.extract_ribbon!
|
186
|
-
|
187
|
-
|
188
|
-
end.
|
192
|
+
path.tap do |path|
|
193
|
+
path.shift unless options.include_root?
|
194
|
+
end.map(&:line).join ' '
|
189
195
|
end
|
190
196
|
|
191
197
|
private
|
data/lib/acclaim/version.rb
CHANGED
@@ -6,8 +6,11 @@ class Test::Command::Subcommand < Test::Command; end
|
|
6
6
|
|
7
7
|
describe Acclaim::Command do
|
8
8
|
|
9
|
+
let(:root_command) { Test::Command }
|
10
|
+
let(:subcommand) { Test::Command::Subcommand }
|
11
|
+
|
9
12
|
describe Test::Command do
|
10
|
-
subject {
|
13
|
+
subject { root_command }
|
11
14
|
|
12
15
|
describe '::line' do
|
13
16
|
context 'when not given a parameter' do
|
@@ -27,6 +30,52 @@ describe Acclaim::Command do
|
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
33
|
+
describe '::full_line' do
|
34
|
+
context 'when not given any options' do
|
35
|
+
it 'should return an empty string' do
|
36
|
+
subject.full_line.should be_empty
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when given an options hash' do
|
41
|
+
context 'which specified that the root command should be excluded' do
|
42
|
+
it 'should return an empty string' do
|
43
|
+
subject.full_line(include_root: false).should be_empty
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'which specified that the root command should be included' do
|
48
|
+
it "should return the command's name" do
|
49
|
+
subject.full_line(include_root: true).should == 'command'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '::root' do
|
56
|
+
it 'should return this command' do
|
57
|
+
subject.root.should == subject
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '::root?' do
|
62
|
+
it 'should return true' do
|
63
|
+
subject.root?.should be_true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '::path' do
|
68
|
+
it 'should return an array containing only the root command itself' do
|
69
|
+
subject.path.should == [ root_command ]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '::parents' do
|
74
|
+
it 'should return an empty array' do
|
75
|
+
subject.parents.should == []
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
30
79
|
describe '::subcommands' do
|
31
80
|
it 'should not be empty' do
|
32
81
|
subject.subcommands.should_not be_empty
|
@@ -39,7 +88,7 @@ describe Acclaim::Command do
|
|
39
88
|
end
|
40
89
|
|
41
90
|
describe Test::Command::Subcommand do
|
42
|
-
subject {
|
91
|
+
subject { subcommand }
|
43
92
|
|
44
93
|
describe '::line' do
|
45
94
|
context 'when not given a parameter' do
|
@@ -59,6 +108,52 @@ describe Acclaim::Command do
|
|
59
108
|
end
|
60
109
|
end
|
61
110
|
|
111
|
+
describe '::full_line' do
|
112
|
+
context 'when not given any options' do
|
113
|
+
it "should return the command's name" do
|
114
|
+
subject.full_line.should == 'subcommand'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'when given an options hash' do
|
119
|
+
context 'which specified that the root command should be excluded' do
|
120
|
+
it "should return the command's name" do
|
121
|
+
subject.full_line(include_root: false).should == 'subcommand'
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'which specified that the root command should be included' do
|
126
|
+
it "should return the command's name prepended by the root command's name" do
|
127
|
+
subject.full_line(include_root: true).should == 'command subcommand'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '::root' do
|
134
|
+
it 'should return the root command' do
|
135
|
+
subject.root.should == root_command
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '::root?' do
|
140
|
+
it 'should return false' do
|
141
|
+
subject.root?.should be_false
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe '::path' do
|
146
|
+
it 'should return an array containing the root command and the subcommand, in order' do
|
147
|
+
subject.path.should == [ root_command, subcommand ]
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe '::parents' do
|
152
|
+
it 'should return the root command' do
|
153
|
+
subject.parents.should == [ root_command ]
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
62
157
|
describe '::subcommands' do
|
63
158
|
it 'should be empty' do
|
64
159
|
subject.subcommands.should be_empty
|
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.
|
4
|
+
version: 0.2.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-
|
12
|
+
date: 2012-01-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ribbon
|
16
|
-
requirement: &
|
16
|
+
requirement: &17374400 !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: *
|
24
|
+
version_requirements: *17374400
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &17373960 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *17373960
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rookie
|
38
|
-
requirement: &
|
38
|
+
requirement: &17373240 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *17373240
|
47
47
|
description: Command-line option parser and command interface.
|
48
48
|
email: matheus.a.m.moreira@gmail.com
|
49
49
|
executables: []
|
@@ -95,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: '0'
|
96
96
|
segments:
|
97
97
|
- 0
|
98
|
-
hash:
|
98
|
+
hash: 3127084049849445509
|
99
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
100
|
none: false
|
101
101
|
requirements:
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
version: '0'
|
105
105
|
segments:
|
106
106
|
- 0
|
107
|
-
hash:
|
107
|
+
hash: 3127084049849445509
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
110
|
rubygems_version: 1.8.10
|