cli/ruby-debug/commands/help.rb in ruby-debug-0.9.3 vs cli/ruby-debug/commands/help.rb in ruby-debug-0.10.0

- old
+ new

@@ -1,35 +1,39 @@ +# Display a list of strings as a compact set of columns. +# +# Each column is only as wide as necessary. +# Columns are separated by two spaces (one was not legible enough). +# Adapted from the routine of the same name in cmd.py + module Debugger class HelpCommand < Command # :nodoc: self.control = true def regexp /^\s*h(?:elp)?(?:\s+(.+))?$/ end def execute - print "ruby-debug help v#{Debugger::VERSION}\n" + print "ruby-debug help v#{Debugger::VERSION}\n" unless + self.class.settings[:debuggertesting] cmds = @state.commands.select{ |cmd| [cmd.help_command].flatten.include?(@match[1]) } unless cmds.empty? help = cmds.map{ |cmd| cmd.help(@match[1]) }.join - print help.split("\n").reject{|l| l =~ /^\s*$/ }.map{|l| l.gsub(/^ +/, '')}.join("\n") + help = help.split("\n").map{|l| l.gsub(/^ +/, '')} + help.shift if help.first && help.first.empty? + help.pop if help.last && help.last.empty? + print help.join("\n") else - print "Type 'help <command-name>' for help on a specific command\n\n" - print "Available commands:\n" - cmds = @state.commands.map{ |cmd| cmd.help_command } - cmds = cmds.flatten.uniq.sort - - buf = "" - cmds.each do |cmd| - if buf.length + cmd.length > 70 - print "%s\n", buf - buf = "#{cmd} " - else - buf << cmd << ' ' - end + if @match[1] + print "Undefined command: \"#{@match[1]}\". Try \"help\"." + else + print "Type 'help <command-name>' for help on a specific command\n\n" + print "Available commands:\n" + cmds = @state.commands.map{ |cmd| cmd.help_command } + cmds = cmds.flatten.uniq.sort + print columnize(cmds, self.class.settings[:width]) end - print "%s\n", buf if buf.length > 0 end print "\n" end class << self @@ -43,6 +47,6 @@ h[elp] command\tprint help on command } end end end -end \ No newline at end of file +end