prompt 1.0.0 → 1.1.0

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.
@@ -2,6 +2,11 @@
2
2
 
3
3
  This is updated when a new version is pushed to http://rubygems.org
4
4
 
5
+ ## 1.1.0 (Apr 18, 2012)
6
+
7
+ * Format help command so that descriptions are always aligned
8
+ * Rescue and print exceptions
9
+
5
10
  ## 1.0.0 (Apr 10, 2012)
6
11
 
7
12
  * Display suggestions when command is not found
@@ -16,22 +16,25 @@ module Prompt
16
16
  print_help true
17
17
  end
18
18
 
19
- command "exit" do
19
+ command "exit", "Exit the console" do
20
20
  exit
21
21
  end
22
22
 
23
23
  private
24
24
 
25
25
  def self.print_help verbose = false
26
+ commands = Prompt.application.commands
27
+ cmd_width = commands.map { |c| c.usage.length }.max
28
+
26
29
  Prompt.application.command_groups.each do |cg|
27
30
  puts
28
31
  puts cg.name
29
32
  puts
30
33
  cg.commands.each do |cmd|
31
- puts " %-40s %s" % [cmd.usage, cmd.desc]
34
+ puts " %-#{cmd_width+4}s %s" % [cmd.usage, cmd.desc]
32
35
  if verbose
33
36
  cmd.parameters.each do |v|
34
- puts " "*43 + ("%-10s %s" % ["<#{v.name}>", "#{v.desc}"])
37
+ puts " "*(cmd_width+7) + ("%-10s %s" % ["<#{v.name}>", "#{v.desc}"])
35
38
  end
36
39
  end
37
40
  end
@@ -38,6 +38,8 @@ module Prompt
38
38
  Prompt.application.exec words
39
39
  rescue CommandNotFound
40
40
  command_not_found line
41
+ rescue => e
42
+ command_exception e
41
43
  end
42
44
  end
43
45
  end
@@ -72,6 +74,11 @@ module Prompt
72
74
  end
73
75
  end
74
76
 
77
+ def self.command_exception e
78
+ puts e.message
79
+ puts e.backtrace.map {|s| " #{s}" }.join("\n")
80
+ end
81
+
75
82
  private
76
83
 
77
84
  S_QUOTED_ARG = /'([^']*)'/
@@ -1,5 +1,5 @@
1
1
  module Prompt
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
 
4
4
  class << self
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prompt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-11 00:00:00.000000000 Z
12
+ date: 2012-04-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Prompt makes it easy to build slick command-line applications with tab
15
15
  completion, command history, and built-in help