cri 2.0a1 → 2.0a2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/cri.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Cri
4
4
 
5
5
  # The current Cri version.
6
- VERSION = '2.0a1'
6
+ VERSION = '2.0a2'
7
7
 
8
8
  autoload 'Command', 'cri/command'
9
9
  autoload 'CommandDSL', 'cri/command_dsl'
@@ -215,7 +215,12 @@ module Cri
215
215
  text = ''
216
216
 
217
217
  # Append usage
218
- text << usage + "\n"
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
- text << "\n"
228
- text << short_desc + "\n"
232
+ if short_desc
233
+ text << "\n"
234
+ text << short_desc + "\n"
235
+ end
229
236
 
230
237
  # Append long description
231
- text << "\n"
232
- text << long_desc.wrap_and_indent(78, 4) + "\n"
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?
@@ -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 'does something super'
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 'does something subby'
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.0a1
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-19 00:00:00 Z
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.