diff --git a/lib/pry/commands/amend_line.rb b/lib/pry/commands/amend_line.rb index e0d51e7a..9ad17abf 100644 --- a/lib/pry/commands/amend_line.rb +++ b/lib/pry/commands/amend_line.rb @@ -1,5 +1,6 @@ class Pry Pry::Commands.create_command(/amend-line(?: (-?\d+)(?:\.\.(-?\d+))?)?/) do + group 'Editing' description "Amend a line of input in multi-line mode." command_options :interpolate => false, :listing => "amend-line" diff --git a/lib/pry/commands/bang.rb b/lib/pry/commands/bang.rb index df02294d..c6a5a338 100644 --- a/lib/pry/commands/bang.rb +++ b/lib/pry/commands/bang.rb @@ -1,5 +1,10 @@ class Pry - Pry::Commands.create_command "!", "Clear the input buffer. Useful if the parsing process goes wrong and you get stuck in the read loop.", :use_prefix => false do + Pry::Commands.create_command "!" do + group 'Editing' + description "Clear the input buffer. Useful if the parsing process goes " \ + "wrong and you get stuck in the read loop." + command_options :use_prefix => false + def process output.puts "Input buffer cleared!" eval_string.replace("") diff --git a/lib/pry/commands/bang_pry.rb b/lib/pry/commands/bang_pry.rb index c9cd7ba0..a37a05f8 100644 --- a/lib/pry/commands/bang_pry.rb +++ b/lib/pry/commands/bang_pry.rb @@ -1,5 +1,11 @@ class Pry - Pry::Commands.command "!pry", "Start a Pry session on current self; this even works mid multi-line expression." do - target.pry + Pry::Commands.create_command "!pry" do + group 'Navigating Pry' + description "Start a Pry session on current self; this even works mid " \ + "multi-line expression." + + def process + target.pry + end end end diff --git a/lib/pry/commands/cat.rb b/lib/pry/commands/cat.rb index c4e9b8f7..d2df7d82 100644 --- a/lib/pry/commands/cat.rb +++ b/lib/pry/commands/cat.rb @@ -1,5 +1,9 @@ class Pry - Pry::Commands.create_command "cat", "Show code from a file, Pry's input buffer, or the last exception." do + Pry::Commands.create_command "cat" do + group 'Input and Output' + description "Show code from a file, Pry's input buffer, or the last " \ + "exception." + banner <<-USAGE Usage: cat FILE cat --ex [STACK_INDEX] diff --git a/lib/pry/commands/edit.rb b/lib/pry/commands/edit.rb index c9187228..36e4ed8f 100644 --- a/lib/pry/commands/edit.rb +++ b/lib/pry/commands/edit.rb @@ -1,5 +1,6 @@ class Pry Pry::Commands.create_command "edit" do + group 'Editing' description "Invoke the default editor on a file." banner <<-BANNER diff --git a/lib/pry/commands/edit_method.rb b/lib/pry/commands/edit_method.rb index eeb42253..7715350f 100644 --- a/lib/pry/commands/edit_method.rb +++ b/lib/pry/commands/edit_method.rb @@ -1,5 +1,6 @@ class Pry Pry::Commands.create_command "edit-method" do + group 'Editing' description "Edit the source code for a method." banner <<-BANNER diff --git a/lib/pry/commands/exit.rb b/lib/pry/commands/exit.rb index 15416081..5de6a102 100644 --- a/lib/pry/commands/exit.rb +++ b/lib/pry/commands/exit.rb @@ -1,5 +1,6 @@ class Pry Pry::Commands.create_command "exit" do + group 'Navigating Pry' description "Pop the previous binding (does NOT exit program). Aliases: quit" banner <<-BANNER diff --git a/lib/pry/commands/exit_all.rb b/lib/pry/commands/exit_all.rb index 972281cd..c31cedaf 100644 --- a/lib/pry/commands/exit_all.rb +++ b/lib/pry/commands/exit_all.rb @@ -1,13 +1,19 @@ class Pry - Pry::Commands.command "exit-all", "End the current Pry session (popping all bindings) and returning to caller. Accepts optional return value. Aliases: !!@" do - # calculate user-given value - exit_value = target.eval(arg_string) + Pry::Commands.create_command "exit-all" do + group 'Navigating Pry' + description "End the current Pry session (popping all bindings) and " \ + "returning to caller. Accepts optional return value. Aliases: !!@" - # clear the binding stack - _pry_.binding_stack.clear + def process + # calculate user-given value + exit_value = target.eval(arg_string) - # break out of the repl loop - throw(:breakout, exit_value) + # clear the binding stack + _pry_.binding_stack.clear + + # break out of the repl loop + throw(:breakout, exit_value) + end end Pry::Commands.alias_command "!!@", "exit-all" diff --git a/lib/pry/commands/exit_program.rb b/lib/pry/commands/exit_program.rb index 561b059b..7d52c0ab 100644 --- a/lib/pry/commands/exit_program.rb +++ b/lib/pry/commands/exit_program.rb @@ -1,7 +1,12 @@ class Pry - Pry::Commands.command "exit-program", "End the current program. Aliases: quit-program, !!!" do - Pry.save_history if Pry.config.history.should_save - Kernel.exit target.eval(arg_string).to_i + Pry::Commands.create_command "exit-program" do + group 'Navigating Pry' + description "End the current program. Aliases: quit-program, !!!" + + def process + Pry.save_history if Pry.config.history.should_save + Kernel.exit target.eval(arg_string).to_i + end end Pry::Commands.alias_command "quit-program", "exit-program" diff --git a/lib/pry/commands/gem_cd.rb b/lib/pry/commands/gem_cd.rb index 7cfb4fc0..fcc0c2e8 100644 --- a/lib/pry/commands/gem_cd.rb +++ b/lib/pry/commands/gem_cd.rb @@ -1,5 +1,9 @@ class Pry - Pry::Commands.create_command "gem-cd", "Change working directory to specified gem's directory.", :argument_required => true do |gem| + Pry::Commands.create_command "gem-cd" do |gem| + group 'Gems' + description "Change working directory to specified gem's directory." + command_options :argument_required => true + banner <<-BANNER Usage: gem-cd GEM_NAME diff --git a/lib/pry/commands/gem_install.rb b/lib/pry/commands/gem_install.rb index 54a7e6cb..f53f5657 100644 --- a/lib/pry/commands/gem_install.rb +++ b/lib/pry/commands/gem_install.rb @@ -1,5 +1,9 @@ class Pry - Pry::Commands.create_command "gem-install", "Install a gem and refresh the gem cache.", :argument_required => true do |gem| + Pry::Commands.create_command "gem-install" do |gem| + group 'Gems' + description "Install a gem and refresh the gem cache." + command_options :argument_required => true + banner <<-BANNER Usage: gem-install GEM_NAME diff --git a/lib/pry/commands/gem_list.rb b/lib/pry/commands/gem_list.rb index 6e88f2cd..de010b0a 100644 --- a/lib/pry/commands/gem_list.rb +++ b/lib/pry/commands/gem_list.rb @@ -1,5 +1,8 @@ class Pry - Pry::Commands.create_command "gem-list", "List and search installed gems." do |pattern| + Pry::Commands.create_command "gem-list" do |pattern| + group 'Gems' + description "List and search installed gems." + banner <<-BANNER Usage: gem-list [REGEX] diff --git a/lib/pry/commands/gist.rb b/lib/pry/commands/gist.rb index 073b9bdf..8052c879 100644 --- a/lib/pry/commands/gist.rb +++ b/lib/pry/commands/gist.rb @@ -1,7 +1,11 @@ class Pry - Pry::Commands.create_command "gist", "Gist a method or expression history to GitHub.", :requires_gem => "jist" do + Pry::Commands.create_command "gist" do include Pry::Helpers::DocumentationHelpers + group 'Misc' + description "Gist a method or expression history to GitHub." + command_options :requires_gem => 'jist', :shellwords => false + banner <<-USAGE Usage: gist [OPTIONS] [METH] Gist method (doc or source) or input expression to GitHub. @@ -17,8 +21,6 @@ class Pry e.g: gist -m my_method --clip # Copy my_method source to clipboard, do not gist it. USAGE - command_options :shellwords => false - attr_accessor :content attr_accessor :filename diff --git a/lib/pry/commands/hist.rb b/lib/pry/commands/hist.rb index 9c3c5d48..055432ce 100644 --- a/lib/pry/commands/hist.rb +++ b/lib/pry/commands/hist.rb @@ -1,6 +1,7 @@ class Pry - Pry::Commands.create_command "hist", "Show and replay Readline history. Aliases: history" do + Pry::Commands.create_command "hist" do group "Editing" + description "Show and replay Readline history. Aliases: history" banner <<-USAGE Usage: hist diff --git a/lib/pry/commands/import_set.rb b/lib/pry/commands/import_set.rb index ab40d4db..348bc95b 100644 --- a/lib/pry/commands/import_set.rb +++ b/lib/pry/commands/import_set.rb @@ -1,6 +1,7 @@ class Pry - Pry::Commands.create_command "import-set", "Import a command set" do + Pry::Commands.create_command "import-set" do group "Commands" + description "Import a command set." def process(command_set_name) raise CommandError, "Provide a command set name" if command_set.nil? diff --git a/lib/pry/commands/install_command.rb b/lib/pry/commands/install_command.rb index 6ad4d878..0e5a4983 100644 --- a/lib/pry/commands/install_command.rb +++ b/lib/pry/commands/install_command.rb @@ -1,6 +1,7 @@ class Pry - Pry::Commands.create_command "install-command", "Install a disabled command." do |name| + Pry::Commands.create_command "install-command" do group 'Commands' + description "Install a disabled command." banner <<-BANNER Usage: install-command COMMAND diff --git a/lib/pry/commands/jump_to.rb b/lib/pry/commands/jump_to.rb index 052c2df1..9769d6f8 100644 --- a/lib/pry/commands/jump_to.rb +++ b/lib/pry/commands/jump_to.rb @@ -1,17 +1,23 @@ class Pry - Pry::Commands.command "jump-to", "Jump to a binding further up the stack, popping all bindings below." do |break_level| - break_level = break_level.to_i - nesting_level = _pry_.binding_stack.size - 1 + Pry::Commands.create_command "jump-to" do + group 'Navigating Pry' + description "Jump to a binding further up the stack, popping all " \ + "bindings below." - case break_level - when nesting_level - output.puts "Already at nesting level #{nesting_level}" - when (0...nesting_level) - _pry_.binding_stack.slice!(break_level + 1, _pry_.binding_stack.size) + def process(break_level) + break_level = break_level.to_i + nesting_level = _pry_.binding_stack.size - 1 - else - max_nest_level = nesting_level - 1 - output.puts "Invalid nest level. Must be between 0 and #{max_nest_level}. Got #{break_level}." + case break_level + when nesting_level + output.puts "Already at nesting level #{nesting_level}" + when (0...nesting_level) + _pry_.binding_stack.slice!(break_level + 1, _pry_.binding_stack.size) + + else + max_nest_level = nesting_level - 1 + output.puts "Invalid nest level. Must be between 0 and #{max_nest_level}. Got #{break_level}." + end end end end diff --git a/lib/pry/commands/ls.rb b/lib/pry/commands/ls.rb index 8e84fafd..86f540cf 100644 --- a/lib/pry/commands/ls.rb +++ b/lib/pry/commands/ls.rb @@ -1,8 +1,8 @@ class Pry - Pry::Commands.create_command "ls","Show the list of vars and methods in the current scope.", - :shellwords => false, :interpolate => false do - + Pry::Commands.create_command "ls" do group "Context" + description "Show the list of vars and methods in the current scope." + command_options :shellwords => false, :interpolate => false def options(opt) opt.banner unindent <<-USAGE diff --git a/lib/pry/commands/nesting.rb b/lib/pry/commands/nesting.rb index d7cb144f..717e8b17 100644 --- a/lib/pry/commands/nesting.rb +++ b/lib/pry/commands/nesting.rb @@ -1,12 +1,17 @@ class Pry - Pry::Commands.command "nesting", "Show nesting information." do - output.puts "Nesting status:" - output.puts "--" - _pry_.binding_stack.each_with_index do |obj, level| - if level == 0 - output.puts "#{level}. #{Pry.view_clip(obj.eval('self'))} (Pry top level)" - else - output.puts "#{level}. #{Pry.view_clip(obj.eval('self'))}" + Pry::Commands.create_command "nesting" do + group 'Navigating Pry' + description "Show nesting information." + + def process + output.puts "Nesting status:" + output.puts "--" + _pry_.binding_stack.each_with_index do |obj, level| + if level == 0 + output.puts "#{level}. #{Pry.view_clip(obj.eval('self'))} (Pry top level)" + else + output.puts "#{level}. #{Pry.view_clip(obj.eval('self'))}" + end end end end diff --git a/lib/pry/commands/play.rb b/lib/pry/commands/play.rb index ee02eb11..9dc18731 100644 --- a/lib/pry/commands/play.rb +++ b/lib/pry/commands/play.rb @@ -2,6 +2,7 @@ class Pry Pry::Commands.create_command "play" do include Pry::Helpers::DocumentationHelpers + group 'Editing' description "Play back a string variable or a method or a file as input." banner <<-BANNER diff --git a/lib/pry/commands/pry_backtrace.rb b/lib/pry/commands/pry_backtrace.rb index 447a310c..aa31e1b6 100644 --- a/lib/pry/commands/pry_backtrace.rb +++ b/lib/pry/commands/pry_backtrace.rb @@ -1,5 +1,8 @@ class Pry - Pry::Commands.create_command "pry-backtrace", "Show the backtrace for the Pry session." do + Pry::Commands.create_command "pry-backtrace" do + group 'Context' + description "Show the backtrace for the Pry session." + banner <<-BANNER Usage: pry-backtrace [OPTIONS] [--help] diff --git a/lib/pry/commands/pry_version.rb b/lib/pry/commands/pry_version.rb index 35cf6500..90301245 100644 --- a/lib/pry/commands/pry_version.rb +++ b/lib/pry/commands/pry_version.rb @@ -1,5 +1,10 @@ class Pry - Pry::Commands.command "pry-version", "Show Pry version." do - output.puts "Pry version: #{Pry::VERSION} on Ruby #{RUBY_VERSION}." + Pry::Commands.create_command "pry-version" do + group 'Misc' + description "Show Pry version." + + def process + output.puts "Pry version: #{Pry::VERSION} on Ruby #{RUBY_VERSION}." + end end end diff --git a/lib/pry/commands/raise_up.rb b/lib/pry/commands/raise_up.rb index 922f6b61..0179343f 100644 --- a/lib/pry/commands/raise_up.rb +++ b/lib/pry/commands/raise_up.rb @@ -1,7 +1,10 @@ class Pry # N.B. using a regular expresion here so that "raise-up 'foo'" does the right thing. - Pry::Commands.create_command(/raise-up(!?\b.*)/, :listing => 'raise-up') do + Pry::Commands.create_command(/raise-up(!?\b.*)/) do + group 'Context' description "Raise an exception out of the current pry instance." + command_options :listing => 'raise-up' + banner <<-BANNER Raise up, like exit, allows you to quit pry. Instead of returning a value however, it raises an exception. If you don't provide the exception to be raised, it will use the most recent exception (in pry _ex_). diff --git a/lib/pry/commands/reload_method.rb b/lib/pry/commands/reload_method.rb index 07821ad4..a94202f2 100644 --- a/lib/pry/commands/reload_method.rb +++ b/lib/pry/commands/reload_method.rb @@ -1,15 +1,20 @@ class Pry - Pry::Commands.command "reload-method", "Reload the source file that contains the specified method" do |meth_name| - meth = get_method_or_raise(meth_name, target, {}, :omit_help) + Pry::Commands.create_command "reload-method" do + group 'Misc' + description "Reload the source file that contains the specified method" - if meth.source_type == :c - raise CommandError, "Can't reload a C method." - elsif meth.dynamically_defined? - raise CommandError, "Can't reload an eval method." - else - file_name = meth.source_file - load file_name - output.puts "Reloaded #{file_name}." + def process(meth_name) + meth = get_method_or_raise(meth_name, target, {}, :omit_help) + + if meth.source_type == :c + raise CommandError, "Can't reload a C method." + elsif meth.dynamically_defined? + raise CommandError, "Can't reload an eval method." + else + file_name = meth.source_file + load file_name + output.puts "Reloaded #{file_name}." + end end end end diff --git a/lib/pry/commands/reset.rb b/lib/pry/commands/reset.rb index 7fe481c8..3d12504c 100644 --- a/lib/pry/commands/reset.rb +++ b/lib/pry/commands/reset.rb @@ -1,6 +1,11 @@ class Pry - Pry::Commands.command "reset", "Reset the REPL to a clean state." do - output.puts "Pry reset." - exec "pry" + Pry::Commands.create_command "reset" do + group 'Context' + description "Reset the REPL to a clean state." + + def process + output.puts "Pry reset." + exec "pry" + end end end diff --git a/lib/pry/commands/ri.rb b/lib/pry/commands/ri.rb index e689e09f..fcb5dd2c 100644 --- a/lib/pry/commands/ri.rb +++ b/lib/pry/commands/ri.rb @@ -1,5 +1,8 @@ class Pry - Pry::Commands.create_command "ri", "View ri documentation. e.g `ri Array#each`" do + Pry::Commands.create_command "ri" do + group 'Introspection' + description "View ri documentation. e.g `ri Array#each`" + banner <<-BANNER Usage: ri [spec] e.g. ri Array#each diff --git a/lib/pry/commands/save_file.rb b/lib/pry/commands/save_file.rb index f0f33baf..33b4798c 100644 --- a/lib/pry/commands/save_file.rb +++ b/lib/pry/commands/save_file.rb @@ -1,5 +1,8 @@ class Pry - Pry::Commands.create_command "save-file", "Export to a file using content from the REPL." do + Pry::Commands.create_command "save-file" do + group 'Input and Output' + description "Export to a file using content from the REPL." + banner <<-USAGE Usage: save-file [OPTIONS] [FILE] Save REPL content to a file. diff --git a/lib/pry/commands/shell_command.rb b/lib/pry/commands/shell_command.rb index 2977ff71..b67379f2 100644 --- a/lib/pry/commands/shell_command.rb +++ b/lib/pry/commands/shell_command.rb @@ -1,19 +1,26 @@ class Pry - Pry::Commands.command(/\.(.*)/, "All text following a '.' is forwarded to the shell.", :listing => ".", :use_prefix => false, :takes_block => true) do |cmd| - if cmd =~ /^cd\s+(.+)/i - dest = $1 - begin - Dir.chdir File.expand_path(dest) - rescue Errno::ENOENT - raise CommandError, "No such directory: #{dest}" - end - else - pass_block(cmd) + Pry::Commands.create_command(/\.(.*)/) do + group 'Input and Output' + description "All text following a '.' is forwarded to the shell." + command_options :listing => ".", :use_prefix => false, + :takes_block => true - if command_block - command_block.call `#{cmd}` + def process(cmd) + if cmd =~ /^cd\s+(.+)/i + dest = $1 + begin + Dir.chdir File.expand_path(dest) + rescue Errno::ENOENT + raise CommandError, "No such directory: #{dest}" + end else - Pry.config.system.call(output, cmd, _pry_) + pass_block(cmd) + + if command_block + command_block.call `#{cmd}` + else + Pry.config.system.call(output, cmd, _pry_) + end end end end diff --git a/lib/pry/commands/shell_mode.rb b/lib/pry/commands/shell_mode.rb index ae923592..53de16fb 100644 --- a/lib/pry/commands/shell_mode.rb +++ b/lib/pry/commands/shell_mode.rb @@ -1,14 +1,19 @@ class Pry - Pry::Commands.command "shell-mode", "Toggle shell mode. Bring in pwd prompt and file completion." do - case _pry_.prompt - when Pry::SHELL_PROMPT - _pry_.pop_prompt - _pry_.custom_completions = Pry::DEFAULT_CUSTOM_COMPLETIONS - else - _pry_.push_prompt Pry::SHELL_PROMPT - _pry_.custom_completions = Pry::FILE_COMPLETIONS - Readline.completion_proc = Pry::InputCompleter.build_completion_proc target, - _pry_.instance_eval(&Pry::FILE_COMPLETIONS) + Pry::Commands.create_command "shell-mode" do + group 'Input and Output' + description "Toggle shell mode. Bring in pwd prompt and file completion." + + def process + case _pry_.prompt + when Pry::SHELL_PROMPT + _pry_.pop_prompt + _pry_.custom_completions = Pry::DEFAULT_CUSTOM_COMPLETIONS + else + _pry_.push_prompt Pry::SHELL_PROMPT + _pry_.custom_completions = Pry::FILE_COMPLETIONS + Readline.completion_proc = Pry::InputCompleter.build_completion_proc target, + _pry_.instance_eval(&Pry::FILE_COMPLETIONS) + end end end diff --git a/lib/pry/commands/show_command.rb b/lib/pry/commands/show_command.rb index e0bdecb1..b65e371a 100644 --- a/lib/pry/commands/show_command.rb +++ b/lib/pry/commands/show_command.rb @@ -1,42 +1,47 @@ class Pry - Pry::Commands.command "show-command", "Show the source for CMD." do |*args| - target = target() + Pry::Commands.create_command "show-command" do + group 'Introspection' + description "Show the source for CMD." - opts = Slop.parse!(args) do |opt| - opt.banner unindent <<-USAGE - Usage: show-command [OPTIONS] [CMD] - Show the source for command CMD. - e.g: show-command show-method - USAGE + def process(*args) + target = target() - opt.on :l, "line-numbers", "Show line numbers." - opt.on :f, :flood, "Do not use a pager to view text longer than one screen." - opt.on :h, :help, "This message." do - output.puts opt.help + opts = Slop.parse!(args) do |opt| + opt.banner unindent <<-USAGE + Usage: show-command [OPTIONS] [CMD] + Show the source for command CMD. + e.g: show-command show-method + USAGE + + opt.on :l, "line-numbers", "Show line numbers." + opt.on :f, :flood, "Do not use a pager to view text longer than one screen." + opt.on :h, :help, "This message." do + output.puts opt.help + end end - end - next if opts.present?(:help) + return if opts.present?(:help) - command_name = args.shift - if !command_name - raise CommandError, "You must provide a command name." - end + command_name = args.shift + if !command_name + raise CommandError, "You must provide a command name." + end - if find_command(command_name) - block = Pry::Method.new(find_command(command_name).block) + if find_command(command_name) + block = Pry::Method.new(find_command(command_name).block) - next unless block.source - set_file_and_dir_locals(block.source_file) + return unless block.source + set_file_and_dir_locals(block.source_file) - output.puts make_header(block) - output.puts + output.puts make_header(block) + output.puts - code = Pry::Code.from_method(block).with_line_numbers(opts.present?(:'line-numbers')).to_s + code = Pry::Code.from_method(block).with_line_numbers(opts.present?(:'line-numbers')).to_s - render_output(code, opts) - else - raise CommandError, "No such command: #{command_name}." + render_output(code, opts) + else + raise CommandError, "No such command: #{command_name}." + end end end end diff --git a/lib/pry/commands/show_doc.rb b/lib/pry/commands/show_doc.rb index 27db66e1..73b4c05d 100644 --- a/lib/pry/commands/show_doc.rb +++ b/lib/pry/commands/show_doc.rb @@ -1,9 +1,14 @@ class Pry - Pry::Commands.create_command "show-doc", "Show the documentation for a method or class. Aliases: \?", :shellwords => false do + Pry::Commands.create_command "show-doc" do include Pry::Helpers::ModuleIntrospectionHelpers include Pry::Helpers::DocumentationHelpers extend Pry::Helpers::BaseHelpers + group 'Introspection' + description "Show the documentation for a method or class. Aliases: \?" + command_options :shellwords => false + command_options :requires_gem => "ruby18_source_location" if mri_18? + banner <<-BANNER Usage: show-doc [OPTIONS] [METH] Aliases: ? @@ -14,8 +19,6 @@ class Pry e.g show-doc Pry -a # docs for all definitions of Pry class (all monkey patches) BANNER - options :requires_gem => "ruby18_source_location" if mri_18? - def setup require 'ruby18_source_location' if mri_18? end diff --git a/lib/pry/commands/show_input.rb b/lib/pry/commands/show_input.rb index 5e6ba0f7..6ae5175d 100644 --- a/lib/pry/commands/show_input.rb +++ b/lib/pry/commands/show_input.rb @@ -1,5 +1,8 @@ class Pry - Pry::Commands.create_command "show-input", "Show the contents of the input buffer for the current multi-line expression." do + Pry::Commands.create_command "show-input" do + group 'Editing' + description "Show the contents of the input buffer for the current multi-line expression." + def process output.puts Code.new(eval_string).with_line_numbers end diff --git a/lib/pry/commands/show_source.rb b/lib/pry/commands/show_source.rb index e38cfca3..11dd60b3 100644 --- a/lib/pry/commands/show_source.rb +++ b/lib/pry/commands/show_source.rb @@ -3,6 +3,7 @@ class Pry include Pry::Helpers::ModuleIntrospectionHelpers extend Pry::Helpers::BaseHelpers + group 'Introspection' description "Show the source for a method or class. Aliases: $, show-method" banner <<-BANNER diff --git a/lib/pry/commands/simple_prompt.rb b/lib/pry/commands/simple_prompt.rb index 7c8163d7..7efbd16c 100644 --- a/lib/pry/commands/simple_prompt.rb +++ b/lib/pry/commands/simple_prompt.rb @@ -1,10 +1,15 @@ class Pry - Pry::Commands.command "simple-prompt", "Toggle the simple prompt." do - case _pry_.prompt - when Pry::SIMPLE_PROMPT - _pry_.pop_prompt - else - _pry_.push_prompt Pry::SIMPLE_PROMPT + Pry::Commands.create_command "simple-prompt" do + group 'Misc' + description "Toggle the simple prompt." + + def process + case _pry_.prompt + when Pry::SIMPLE_PROMPT + _pry_.pop_prompt + else + _pry_.push_prompt Pry::SIMPLE_PROMPT + end end end end diff --git a/lib/pry/commands/stat.rb b/lib/pry/commands/stat.rb index 8870cb0c..84a3c47f 100644 --- a/lib/pry/commands/stat.rb +++ b/lib/pry/commands/stat.rb @@ -1,5 +1,9 @@ class Pry - Pry::Commands.create_command "stat", "View method information and set _file_ and _dir_ locals.", :shellwords => false do + Pry::Commands.create_command "stat" do + group 'Introspection' + description "View method information and set _file_ and _dir_ locals." + command_options :shellwords => false + banner <<-BANNER Usage: stat [OPTIONS] [METH] Show method information for method METH and set _file_ and _dir_ locals. diff --git a/lib/pry/commands/switch_to.rb b/lib/pry/commands/switch_to.rb index da426d73..10d9adf6 100644 --- a/lib/pry/commands/switch_to.rb +++ b/lib/pry/commands/switch_to.rb @@ -1,11 +1,17 @@ class Pry - Pry::Commands.command "switch-to", "Start a new sub-session on a binding in the current stack (numbered by nesting)." do |selection| - selection = selection.to_i + Pry::Commands.create_command "switch-to" do + group 'Navigating Pry' + description "Start a new sub-session on a binding in the current stack " \ + "(numbered by nesting)." - if selection < 0 || selection > _pry_.binding_stack.size - 1 - raise CommandError, "Invalid binding index #{selection} - use `nesting` command to view valid indices." - else - Pry.start(_pry_.binding_stack[selection]) + def process(selection) + selection = selection.to_i + + if selection < 0 || selection > _pry_.binding_stack.size - 1 + raise CommandError, "Invalid binding index #{selection} - use `nesting` command to view valid indices." + else + Pry.start(_pry_.binding_stack[selection]) + end end end end diff --git a/lib/pry/commands/toggle_color.rb b/lib/pry/commands/toggle_color.rb index b1e5750c..9c34a783 100644 --- a/lib/pry/commands/toggle_color.rb +++ b/lib/pry/commands/toggle_color.rb @@ -1,6 +1,11 @@ class Pry - Pry::Commands.command "toggle-color", "Toggle syntax highlighting." do - Pry.color = !Pry.color - output.puts "Syntax highlighting #{Pry.color ? "on" : "off"}" + Pry::Commands.create_command "toggle-color" do + group 'Misc' + description "Toggle syntax highlighting." + + def process + Pry.color = !Pry.color + output.puts "Syntax highlighting #{Pry.color ? "on" : "off"}" + end end end diff --git a/lib/pry/commands/wtf.rb b/lib/pry/commands/wtf.rb index f56d34b8..a01efda6 100644 --- a/lib/pry/commands/wtf.rb +++ b/lib/pry/commands/wtf.rb @@ -1,5 +1,7 @@ class Pry - Pry::Commands.create_command(/wtf([?!]*)/, "Show the backtrace of the most recent exception") do + Pry::Commands.create_command(/wtf([?!]*)/) do + group 'Context' + description "Show the backtrace of the most recent exception" options :listing => 'wtf?' banner <<-BANNER