cri 2.0a1 → 2.0a2
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/cri.rb +1 -1
- data/lib/cri/command.rb +14 -5
- data/test/test_command.rb +21 -2
- metadata +2 -2
data/lib/cri.rb
CHANGED
data/lib/cri/command.rb
CHANGED
@@ -215,7 +215,12 @@ module Cri
|
|
215
215
|
text = ''
|
216
216
|
|
217
217
|
# Append usage
|
218
|
-
|
218
|
+
if usage
|
219
|
+
path = [ self.supercommand ]
|
220
|
+
path.unshift(path[0].supercommand) until path[0].nil?
|
221
|
+
full_usage = path[1..-1].map { |c| c.name + ' ' }.join + usage
|
222
|
+
text << "usage: #{full_usage}\n"
|
223
|
+
end
|
219
224
|
|
220
225
|
# Append aliases
|
221
226
|
unless aliases.empty?
|
@@ -224,12 +229,16 @@ module Cri
|
|
224
229
|
end
|
225
230
|
|
226
231
|
# Append short description
|
227
|
-
|
228
|
-
|
232
|
+
if short_desc
|
233
|
+
text << "\n"
|
234
|
+
text << short_desc + "\n"
|
235
|
+
end
|
229
236
|
|
230
237
|
# Append long description
|
231
|
-
|
232
|
-
|
238
|
+
if long_desc
|
239
|
+
text << "\n"
|
240
|
+
text << long_desc.wrap_and_indent(78, 4) + "\n"
|
241
|
+
end
|
233
242
|
|
234
243
|
# Append subcommands
|
235
244
|
unless self.commands.empty?
|
data/test/test_command.rb
CHANGED
@@ -29,10 +29,19 @@ class Cri::CommandTestCase < Cri::TestCase
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
def bare_cmd
|
33
|
+
Cri::Command.define do
|
34
|
+
name 'moo'
|
35
|
+
|
36
|
+
run do |opts, args|
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
32
41
|
def nested_cmd
|
33
42
|
super_cmd = Cri::Command.define do
|
34
43
|
name 'super'
|
35
|
-
usage '
|
44
|
+
usage 'super [command] [options] [arguments]'
|
36
45
|
summary 'does super stuff'
|
37
46
|
description 'This command does super stuff.'
|
38
47
|
|
@@ -48,7 +57,7 @@ class Cri::CommandTestCase < Cri::TestCase
|
|
48
57
|
super_cmd.define_command do
|
49
58
|
name 'sub'
|
50
59
|
aliases 'sup'
|
51
|
-
usage '
|
60
|
+
usage 'sub [options]'
|
52
61
|
summary 'does subby stuff'
|
53
62
|
description 'This command does subby stuff.'
|
54
63
|
|
@@ -201,6 +210,16 @@ class Cri::CommandTestCase < Cri::TestCase
|
|
201
210
|
assert_equal [ ], lines(err)
|
202
211
|
end
|
203
212
|
|
213
|
+
def test_help_nested
|
214
|
+
help = nested_cmd.subcommands.to_a[0].help
|
215
|
+
|
216
|
+
assert_match /^usage: super sub \[options\]/, help
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_help_for_bare_cmd
|
220
|
+
bare_cmd.help
|
221
|
+
end
|
222
|
+
|
204
223
|
def test_modify
|
205
224
|
cmd = Cri::Command.define do
|
206
225
|
name 'build'
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: cri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 3
|
5
|
-
version: 2.
|
5
|
+
version: 2.0a2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Denis Defreyne
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-20 00:00:00 Z
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: Cri allows building easy-to-use commandline interfaces with support for subcommands.
|