pry 0.10.0.pre2-universal-mingw32
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.
- checksums.yaml +7 -0
 - data/CHANGELOG.md +702 -0
 - data/LICENSE +25 -0
 - data/README.md +406 -0
 - data/bin/pry +16 -0
 - data/lib/pry.rb +161 -0
 - data/lib/pry/cli.rb +220 -0
 - data/lib/pry/code.rb +346 -0
 - data/lib/pry/code/code_file.rb +103 -0
 - data/lib/pry/code/code_range.rb +71 -0
 - data/lib/pry/code/loc.rb +92 -0
 - data/lib/pry/code_object.rb +172 -0
 - data/lib/pry/color_printer.rb +55 -0
 - data/lib/pry/command.rb +692 -0
 - data/lib/pry/command_set.rb +443 -0
 - data/lib/pry/commands.rb +6 -0
 - data/lib/pry/commands/amend_line.rb +99 -0
 - data/lib/pry/commands/bang.rb +20 -0
 - data/lib/pry/commands/bang_pry.rb +17 -0
 - data/lib/pry/commands/cat.rb +62 -0
 - data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
 - data/lib/pry/commands/cat/exception_formatter.rb +77 -0
 - data/lib/pry/commands/cat/file_formatter.rb +67 -0
 - data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
 - data/lib/pry/commands/cd.rb +41 -0
 - data/lib/pry/commands/change_inspector.rb +27 -0
 - data/lib/pry/commands/change_prompt.rb +26 -0
 - data/lib/pry/commands/code_collector.rb +165 -0
 - data/lib/pry/commands/disable_pry.rb +27 -0
 - data/lib/pry/commands/disabled_commands.rb +2 -0
 - data/lib/pry/commands/easter_eggs.rb +112 -0
 - data/lib/pry/commands/edit.rb +195 -0
 - data/lib/pry/commands/edit/exception_patcher.rb +25 -0
 - data/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
 - data/lib/pry/commands/exit.rb +42 -0
 - data/lib/pry/commands/exit_all.rb +29 -0
 - data/lib/pry/commands/exit_program.rb +23 -0
 - data/lib/pry/commands/find_method.rb +193 -0
 - data/lib/pry/commands/fix_indent.rb +19 -0
 - data/lib/pry/commands/gem_cd.rb +26 -0
 - data/lib/pry/commands/gem_install.rb +32 -0
 - data/lib/pry/commands/gem_list.rb +33 -0
 - data/lib/pry/commands/gem_open.rb +29 -0
 - data/lib/pry/commands/gist.rb +101 -0
 - data/lib/pry/commands/help.rb +164 -0
 - data/lib/pry/commands/hist.rb +180 -0
 - data/lib/pry/commands/import_set.rb +22 -0
 - data/lib/pry/commands/install_command.rb +53 -0
 - data/lib/pry/commands/jump_to.rb +29 -0
 - data/lib/pry/commands/list_inspectors.rb +35 -0
 - data/lib/pry/commands/list_prompts.rb +35 -0
 - data/lib/pry/commands/ls.rb +114 -0
 - data/lib/pry/commands/ls/constants.rb +47 -0
 - data/lib/pry/commands/ls/formatter.rb +49 -0
 - data/lib/pry/commands/ls/globals.rb +48 -0
 - data/lib/pry/commands/ls/grep.rb +21 -0
 - data/lib/pry/commands/ls/instance_vars.rb +39 -0
 - data/lib/pry/commands/ls/interrogatable.rb +18 -0
 - data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
 - data/lib/pry/commands/ls/local_names.rb +35 -0
 - data/lib/pry/commands/ls/local_vars.rb +39 -0
 - data/lib/pry/commands/ls/ls_entity.rb +70 -0
 - data/lib/pry/commands/ls/methods.rb +57 -0
 - data/lib/pry/commands/ls/methods_helper.rb +46 -0
 - data/lib/pry/commands/ls/self_methods.rb +32 -0
 - data/lib/pry/commands/nesting.rb +25 -0
 - data/lib/pry/commands/play.rb +103 -0
 - data/lib/pry/commands/pry_backtrace.rb +25 -0
 - data/lib/pry/commands/pry_version.rb +17 -0
 - data/lib/pry/commands/raise_up.rb +32 -0
 - data/lib/pry/commands/reload_code.rb +62 -0
 - data/lib/pry/commands/reset.rb +18 -0
 - data/lib/pry/commands/ri.rb +60 -0
 - data/lib/pry/commands/save_file.rb +61 -0
 - data/lib/pry/commands/shell_command.rb +48 -0
 - data/lib/pry/commands/shell_mode.rb +25 -0
 - data/lib/pry/commands/show_doc.rb +83 -0
 - data/lib/pry/commands/show_info.rb +195 -0
 - data/lib/pry/commands/show_input.rb +17 -0
 - data/lib/pry/commands/show_source.rb +50 -0
 - data/lib/pry/commands/simple_prompt.rb +22 -0
 - data/lib/pry/commands/stat.rb +40 -0
 - data/lib/pry/commands/switch_to.rb +23 -0
 - data/lib/pry/commands/toggle_color.rb +24 -0
 - data/lib/pry/commands/watch_expression.rb +105 -0
 - data/lib/pry/commands/watch_expression/expression.rb +38 -0
 - data/lib/pry/commands/whereami.rb +190 -0
 - data/lib/pry/commands/wtf.rb +57 -0
 - data/lib/pry/config.rb +24 -0
 - data/lib/pry/config/behavior.rb +139 -0
 - data/lib/pry/config/convenience.rb +26 -0
 - data/lib/pry/config/default.rb +165 -0
 - data/lib/pry/core_extensions.rb +131 -0
 - data/lib/pry/editor.rb +133 -0
 - data/lib/pry/exceptions.rb +77 -0
 - data/lib/pry/helpers.rb +5 -0
 - data/lib/pry/helpers/base_helpers.rb +113 -0
 - data/lib/pry/helpers/command_helpers.rb +156 -0
 - data/lib/pry/helpers/documentation_helpers.rb +75 -0
 - data/lib/pry/helpers/options_helpers.rb +27 -0
 - data/lib/pry/helpers/table.rb +109 -0
 - data/lib/pry/helpers/text.rb +107 -0
 - data/lib/pry/history.rb +125 -0
 - data/lib/pry/history_array.rb +121 -0
 - data/lib/pry/hooks.rb +230 -0
 - data/lib/pry/indent.rb +406 -0
 - data/lib/pry/input_completer.rb +242 -0
 - data/lib/pry/input_lock.rb +132 -0
 - data/lib/pry/inspector.rb +27 -0
 - data/lib/pry/last_exception.rb +61 -0
 - data/lib/pry/method.rb +546 -0
 - data/lib/pry/method/disowned.rb +53 -0
 - data/lib/pry/method/patcher.rb +125 -0
 - data/lib/pry/method/weird_method_locator.rb +186 -0
 - data/lib/pry/module_candidate.rb +136 -0
 - data/lib/pry/object_path.rb +82 -0
 - data/lib/pry/output.rb +50 -0
 - data/lib/pry/pager.rb +234 -0
 - data/lib/pry/plugins.rb +103 -0
 - data/lib/pry/prompt.rb +26 -0
 - data/lib/pry/pry_class.rb +375 -0
 - data/lib/pry/pry_instance.rb +654 -0
 - data/lib/pry/rbx_path.rb +22 -0
 - data/lib/pry/repl.rb +202 -0
 - data/lib/pry/repl_file_loader.rb +74 -0
 - data/lib/pry/rubygem.rb +82 -0
 - data/lib/pry/terminal.rb +79 -0
 - data/lib/pry/test/helper.rb +170 -0
 - data/lib/pry/version.rb +3 -0
 - data/lib/pry/wrapped_module.rb +373 -0
 - metadata +248 -0
 
| 
         @@ -0,0 +1,164 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Pry
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Command::Help < Pry::ClassCommand
         
     | 
| 
      
 3 
     | 
    
         
            +
                match 'help'
         
     | 
| 
      
 4 
     | 
    
         
            +
                group 'Help'
         
     | 
| 
      
 5 
     | 
    
         
            +
                description 'Show a list of commands or information about a specific command.'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                banner <<-'BANNER'
         
     | 
| 
      
 8 
     | 
    
         
            +
                  Usage: help [COMMAND]
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                  With no arguments, help lists all the available commands along with their
         
     | 
| 
      
 11 
     | 
    
         
            +
                  descriptions. When given a command name as an argument, shows the help
         
     | 
| 
      
 12 
     | 
    
         
            +
                  for that command.
         
     | 
| 
      
 13 
     | 
    
         
            +
                BANNER
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                # We only want to show commands that have descriptions, so that the
         
     | 
| 
      
 16 
     | 
    
         
            +
                # easter eggs don't show up.
         
     | 
| 
      
 17 
     | 
    
         
            +
                def visible_commands
         
     | 
| 
      
 18 
     | 
    
         
            +
                  visible = {}
         
     | 
| 
      
 19 
     | 
    
         
            +
                  commands.each do |key, command|
         
     | 
| 
      
 20 
     | 
    
         
            +
                    visible[key] = command if command.description && !command.description.empty?
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
                  visible
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                # Get a hash of available commands grouped by the "group" name.
         
     | 
| 
      
 26 
     | 
    
         
            +
                def command_groups
         
     | 
| 
      
 27 
     | 
    
         
            +
                  visible_commands.values.group_by(&:group)
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                def process
         
     | 
| 
      
 31 
     | 
    
         
            +
                  if args.empty?
         
     | 
| 
      
 32 
     | 
    
         
            +
                    display_index(command_groups)
         
     | 
| 
      
 33 
     | 
    
         
            +
                  else
         
     | 
| 
      
 34 
     | 
    
         
            +
                    display_search(args.first)
         
     | 
| 
      
 35 
     | 
    
         
            +
                  end
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                # Display the index view, with headings and short descriptions per command.
         
     | 
| 
      
 39 
     | 
    
         
            +
                #
         
     | 
| 
      
 40 
     | 
    
         
            +
                # @param [Hash<String, Array<Commands>>] groups
         
     | 
| 
      
 41 
     | 
    
         
            +
                def display_index(groups)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  help_text = []
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                  sorted_group_names(groups).each do |group_name|
         
     | 
| 
      
 45 
     | 
    
         
            +
                    commands = sorted_commands(groups[group_name])
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                    if commands.any?
         
     | 
| 
      
 48 
     | 
    
         
            +
                       help_text << help_text_for_commands(group_name, commands)
         
     | 
| 
      
 49 
     | 
    
         
            +
                    end
         
     | 
| 
      
 50 
     | 
    
         
            +
                  end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                  _pry_.pager.page help_text.join("\n\n")
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                # Given a group name and an array of commands,
         
     | 
| 
      
 56 
     | 
    
         
            +
                # return the help string for those commands.
         
     | 
| 
      
 57 
     | 
    
         
            +
                #
         
     | 
| 
      
 58 
     | 
    
         
            +
                # @param [String] name The group name.
         
     | 
| 
      
 59 
     | 
    
         
            +
                # @param [Array<Pry::Command>] commands
         
     | 
| 
      
 60 
     | 
    
         
            +
                # @return [String] The generated help string.
         
     | 
| 
      
 61 
     | 
    
         
            +
                def help_text_for_commands(name, commands)
         
     | 
| 
      
 62 
     | 
    
         
            +
                  "#{text.bold(name.capitalize)}\n" << commands.map do |command|
         
     | 
| 
      
 63 
     | 
    
         
            +
                    "  #{command.options[:listing].to_s.ljust(18)} #{command.description.capitalize}"
         
     | 
| 
      
 64 
     | 
    
         
            +
                  end.join("\n")
         
     | 
| 
      
 65 
     | 
    
         
            +
                end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                # @param [Hash] groups
         
     | 
| 
      
 68 
     | 
    
         
            +
                # @return [Array<String>] An array of sorted group names.
         
     | 
| 
      
 69 
     | 
    
         
            +
                def sorted_group_names(groups)
         
     | 
| 
      
 70 
     | 
    
         
            +
                  groups.keys.sort_by(&method(:group_sort_key))
         
     | 
| 
      
 71 
     | 
    
         
            +
                end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                # Sort an array of commands by their `listing` name.
         
     | 
| 
      
 74 
     | 
    
         
            +
                #
         
     | 
| 
      
 75 
     | 
    
         
            +
                # @param [Array<Pry::Command>] commands The commands to sort
         
     | 
| 
      
 76 
     | 
    
         
            +
                # @return [Array<Pry::Command>] commands sorted by listing name.
         
     | 
| 
      
 77 
     | 
    
         
            +
                def sorted_commands(commands)
         
     | 
| 
      
 78 
     | 
    
         
            +
                  commands.sort_by{ |command| command.options[:listing].to_s }
         
     | 
| 
      
 79 
     | 
    
         
            +
                end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                # Display help for an individual command or group.
         
     | 
| 
      
 82 
     | 
    
         
            +
                #
         
     | 
| 
      
 83 
     | 
    
         
            +
                # @param [String] search  The string to search for.
         
     | 
| 
      
 84 
     | 
    
         
            +
                def display_search(search)
         
     | 
| 
      
 85 
     | 
    
         
            +
                  if command = command_set.find_command_for_help(search)
         
     | 
| 
      
 86 
     | 
    
         
            +
                    display_command(command)
         
     | 
| 
      
 87 
     | 
    
         
            +
                  else
         
     | 
| 
      
 88 
     | 
    
         
            +
                    display_filtered_search_results(search)
         
     | 
| 
      
 89 
     | 
    
         
            +
                  end
         
     | 
| 
      
 90 
     | 
    
         
            +
                end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                # Display help for a searched item, filtered first by group
         
     | 
| 
      
 93 
     | 
    
         
            +
                # and if that fails, filtered by command name.
         
     | 
| 
      
 94 
     | 
    
         
            +
                #
         
     | 
| 
      
 95 
     | 
    
         
            +
                # @param [String] search The string to search for.
         
     | 
| 
      
 96 
     | 
    
         
            +
                def display_filtered_search_results(search)
         
     | 
| 
      
 97 
     | 
    
         
            +
                  groups = search_hash(search, command_groups)
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                  if groups.size > 0
         
     | 
| 
      
 100 
     | 
    
         
            +
                    display_index(groups)
         
     | 
| 
      
 101 
     | 
    
         
            +
                  else
         
     | 
| 
      
 102 
     | 
    
         
            +
                    display_filtered_commands(search)
         
     | 
| 
      
 103 
     | 
    
         
            +
                  end
         
     | 
| 
      
 104 
     | 
    
         
            +
                end
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
                # Display help for a searched item, filtered by group
         
     | 
| 
      
 107 
     | 
    
         
            +
                #
         
     | 
| 
      
 108 
     | 
    
         
            +
                # @param [String] search The string to search for.
         
     | 
| 
      
 109 
     | 
    
         
            +
                def display_filtered_commands(search)
         
     | 
| 
      
 110 
     | 
    
         
            +
                  filtered = search_hash(search, visible_commands)
         
     | 
| 
      
 111 
     | 
    
         
            +
                  raise CommandError, "No help found for '#{args.first}'" if filtered.empty?
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                  if filtered.size == 1
         
     | 
| 
      
 114 
     | 
    
         
            +
                    display_command(filtered.values.first)
         
     | 
| 
      
 115 
     | 
    
         
            +
                  else
         
     | 
| 
      
 116 
     | 
    
         
            +
                    display_index({"'#{search}' commands" => filtered.values})
         
     | 
| 
      
 117 
     | 
    
         
            +
                  end
         
     | 
| 
      
 118 
     | 
    
         
            +
                end
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
                # Display help for an individual command.
         
     | 
| 
      
 121 
     | 
    
         
            +
                #
         
     | 
| 
      
 122 
     | 
    
         
            +
                # @param [Pry::Command] command
         
     | 
| 
      
 123 
     | 
    
         
            +
                def display_command(command)
         
     | 
| 
      
 124 
     | 
    
         
            +
                  _pry_.pager.page command.new.help
         
     | 
| 
      
 125 
     | 
    
         
            +
                end
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
                # Find a subset of a hash that matches the user's search term.
         
     | 
| 
      
 128 
     | 
    
         
            +
                #
         
     | 
| 
      
 129 
     | 
    
         
            +
                # If there's an exact match a Hash of one element will be returned,
         
     | 
| 
      
 130 
     | 
    
         
            +
                # otherwise a sub-Hash with every key that matches the search will
         
     | 
| 
      
 131 
     | 
    
         
            +
                # be returned.
         
     | 
| 
      
 132 
     | 
    
         
            +
                #
         
     | 
| 
      
 133 
     | 
    
         
            +
                # @param [String] search the search term
         
     | 
| 
      
 134 
     | 
    
         
            +
                # @param [Hash] hash the hash to search
         
     | 
| 
      
 135 
     | 
    
         
            +
                def search_hash(search, hash)
         
     | 
| 
      
 136 
     | 
    
         
            +
                  matching = {}
         
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
                  hash.each_pair do |key, value|
         
     | 
| 
      
 139 
     | 
    
         
            +
                    next unless key.is_a?(String)
         
     | 
| 
      
 140 
     | 
    
         
            +
                    if normalize(key) == normalize(search)
         
     | 
| 
      
 141 
     | 
    
         
            +
                      return {key => value}
         
     | 
| 
      
 142 
     | 
    
         
            +
                    elsif normalize(key).start_with?(normalize(search))
         
     | 
| 
      
 143 
     | 
    
         
            +
                      matching[key] = value
         
     | 
| 
      
 144 
     | 
    
         
            +
                    end
         
     | 
| 
      
 145 
     | 
    
         
            +
                  end
         
     | 
| 
      
 146 
     | 
    
         
            +
             
     | 
| 
      
 147 
     | 
    
         
            +
                  matching
         
     | 
| 
      
 148 
     | 
    
         
            +
                end
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
                # Clean search terms to make it easier to search group names
         
     | 
| 
      
 151 
     | 
    
         
            +
                #
         
     | 
| 
      
 152 
     | 
    
         
            +
                # @param [String] key
         
     | 
| 
      
 153 
     | 
    
         
            +
                # @return [String]
         
     | 
| 
      
 154 
     | 
    
         
            +
                def normalize(key)
         
     | 
| 
      
 155 
     | 
    
         
            +
                  key.downcase.gsub(/pry\W+/, '')
         
     | 
| 
      
 156 
     | 
    
         
            +
                end
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
                def group_sort_key(group_name)
         
     | 
| 
      
 159 
     | 
    
         
            +
                  [%w(Help Context Editing Introspection Input_and_output Navigating_pry Gems Basic Commands).index(group_name.gsub(' ', '_')) || 99, group_name]
         
     | 
| 
      
 160 
     | 
    
         
            +
                end
         
     | 
| 
      
 161 
     | 
    
         
            +
              end
         
     | 
| 
      
 162 
     | 
    
         
            +
             
     | 
| 
      
 163 
     | 
    
         
            +
              Pry::Commands.add_command(Pry::Command::Help)
         
     | 
| 
      
 164 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,180 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Pry
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Command::Hist < Pry::ClassCommand
         
     | 
| 
      
 3 
     | 
    
         
            +
                match 'hist'
         
     | 
| 
      
 4 
     | 
    
         
            +
                group 'Editing'
         
     | 
| 
      
 5 
     | 
    
         
            +
                description 'Show and replay Readline history.'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                banner <<-'BANNER'
         
     | 
| 
      
 8 
     | 
    
         
            +
                  Usage:   hist [--head|--tail]
         
     | 
| 
      
 9 
     | 
    
         
            +
                           hist --all
         
     | 
| 
      
 10 
     | 
    
         
            +
                           hist --head N
         
     | 
| 
      
 11 
     | 
    
         
            +
                           hist --tail N
         
     | 
| 
      
 12 
     | 
    
         
            +
                           hist --show START..END
         
     | 
| 
      
 13 
     | 
    
         
            +
                           hist --grep PATTERN
         
     | 
| 
      
 14 
     | 
    
         
            +
                           hist --clear
         
     | 
| 
      
 15 
     | 
    
         
            +
                           hist --replay START..END
         
     | 
| 
      
 16 
     | 
    
         
            +
                           hist --save [START..END] FILE
         
     | 
| 
      
 17 
     | 
    
         
            +
                  Aliases: history
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                  Show and replay Readline history.
         
     | 
| 
      
 20 
     | 
    
         
            +
                BANNER
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                def options(opt)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  opt.on :a, :all,    "Display all history"
         
     | 
| 
      
 24 
     | 
    
         
            +
                  opt.on :H, :head,   "Display the first N items", :optional_argument => true, :as => Integer
         
     | 
| 
      
 25 
     | 
    
         
            +
                  opt.on :T, :tail,   "Display the last N items", :optional_argument => true, :as => Integer
         
     | 
| 
      
 26 
     | 
    
         
            +
                  opt.on :s, :show,   "Show the given range of lines", :optional_argument => true, :as => Range
         
     | 
| 
      
 27 
     | 
    
         
            +
                  opt.on :G, :grep,   "Show lines matching the given pattern", :argument => true, :as => String
         
     | 
| 
      
 28 
     | 
    
         
            +
                  opt.on :c, :clear , "Clear the current session's history"
         
     | 
| 
      
 29 
     | 
    
         
            +
                  opt.on :r, :replay, "Replay a line or range of lines", :argument => true, :as => Range
         
     | 
| 
      
 30 
     | 
    
         
            +
                  opt.on     :save,   "Save history to a file", :argument => true, :as => Range
         
     | 
| 
      
 31 
     | 
    
         
            +
                  opt.on :e, :'exclude-pry', "Exclude Pry commands from the history"
         
     | 
| 
      
 32 
     | 
    
         
            +
                  opt.on :n, :'no-numbers',  "Omit line numbers"
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                def process
         
     | 
| 
      
 36 
     | 
    
         
            +
                  @history = find_history
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                  if opts.present?(:show)
         
     | 
| 
      
 39 
     | 
    
         
            +
                    @history = @history.between(opts[:show])
         
     | 
| 
      
 40 
     | 
    
         
            +
                  end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                  if opts.present?(:grep)
         
     | 
| 
      
 43 
     | 
    
         
            +
                    @history = @history.grep(opts[:grep])
         
     | 
| 
      
 44 
     | 
    
         
            +
                  end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                  @history = case
         
     | 
| 
      
 47 
     | 
    
         
            +
                    when opts.present?(:head)
         
     | 
| 
      
 48 
     | 
    
         
            +
                      @history.take_lines(1, opts[:head] || 10)
         
     | 
| 
      
 49 
     | 
    
         
            +
                    when opts.present?(:tail)
         
     | 
| 
      
 50 
     | 
    
         
            +
                      @history.take_lines(-(opts[:tail] || 10), opts[:tail] || 10)
         
     | 
| 
      
 51 
     | 
    
         
            +
                    when opts.present?(:show)
         
     | 
| 
      
 52 
     | 
    
         
            +
                      @history.between(opts[:show])
         
     | 
| 
      
 53 
     | 
    
         
            +
                    else
         
     | 
| 
      
 54 
     | 
    
         
            +
                      @history
         
     | 
| 
      
 55 
     | 
    
         
            +
                    end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                  if opts.present?(:'exclude-pry')
         
     | 
| 
      
 58 
     | 
    
         
            +
                    @history = @history.select do |loc|
         
     | 
| 
      
 59 
     | 
    
         
            +
                                 !command_set.valid_command?(loc.line)
         
     | 
| 
      
 60 
     | 
    
         
            +
                               end
         
     | 
| 
      
 61 
     | 
    
         
            +
                  end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                  if opts.present?(:save)
         
     | 
| 
      
 64 
     | 
    
         
            +
                    process_save
         
     | 
| 
      
 65 
     | 
    
         
            +
                  elsif opts.present?(:clear)
         
     | 
| 
      
 66 
     | 
    
         
            +
                    process_clear
         
     | 
| 
      
 67 
     | 
    
         
            +
                  elsif opts.present?(:replay)
         
     | 
| 
      
 68 
     | 
    
         
            +
                    process_replay
         
     | 
| 
      
 69 
     | 
    
         
            +
                  else
         
     | 
| 
      
 70 
     | 
    
         
            +
                    process_display
         
     | 
| 
      
 71 
     | 
    
         
            +
                  end
         
     | 
| 
      
 72 
     | 
    
         
            +
                end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                private
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                def process_display
         
     | 
| 
      
 77 
     | 
    
         
            +
                  unless opts.present?(:'no-numbers')
         
     | 
| 
      
 78 
     | 
    
         
            +
                    @history = @history.with_line_numbers
         
     | 
| 
      
 79 
     | 
    
         
            +
                  end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                  _pry_.pager.open do |pager|
         
     | 
| 
      
 82 
     | 
    
         
            +
                    @history.print_to_output(pager, true)
         
     | 
| 
      
 83 
     | 
    
         
            +
                  end
         
     | 
| 
      
 84 
     | 
    
         
            +
                end
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                def process_save
         
     | 
| 
      
 87 
     | 
    
         
            +
                  case opts[:save]
         
     | 
| 
      
 88 
     | 
    
         
            +
                  when Range
         
     | 
| 
      
 89 
     | 
    
         
            +
                    @history = @history.between(opts[:save])
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                    unless args.first
         
     | 
| 
      
 92 
     | 
    
         
            +
                      raise CommandError, "Must provide a file name."
         
     | 
| 
      
 93 
     | 
    
         
            +
                    end
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                    file_name = File.expand_path(args.first)
         
     | 
| 
      
 96 
     | 
    
         
            +
                  when String
         
     | 
| 
      
 97 
     | 
    
         
            +
                    file_name = File.expand_path(opts[:save])
         
     | 
| 
      
 98 
     | 
    
         
            +
                  end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                  output.puts "Saving history in #{file_name}..."
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
                  File.open(file_name, 'w') { |f| f.write(@history.raw) }
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                  output.puts "History saved."
         
     | 
| 
      
 105 
     | 
    
         
            +
                end
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
                def process_clear
         
     | 
| 
      
 108 
     | 
    
         
            +
                  Pry.history.clear
         
     | 
| 
      
 109 
     | 
    
         
            +
                  output.puts "History cleared."
         
     | 
| 
      
 110 
     | 
    
         
            +
                end
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                def process_replay
         
     | 
| 
      
 113 
     | 
    
         
            +
                  @history = @history.between(opts[:r])
         
     | 
| 
      
 114 
     | 
    
         
            +
                  replay_sequence = @history.raw
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
                  # If we met follow-up "hist" call, check for the "--replay" option
         
     | 
| 
      
 117 
     | 
    
         
            +
                  # presence. If "hist" command is called with other options, proceed
         
     | 
| 
      
 118 
     | 
    
         
            +
                  # further.
         
     | 
| 
      
 119 
     | 
    
         
            +
                  check_for_juxtaposed_replay(replay_sequence)
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
                  replay_sequence.lines.each do |line|
         
     | 
| 
      
 122 
     | 
    
         
            +
                    _pry_.eval line, :generated => true
         
     | 
| 
      
 123 
     | 
    
         
            +
                  end
         
     | 
| 
      
 124 
     | 
    
         
            +
                end
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                # Checks +replay_sequence+ for the presence of neighboring replay calls.
         
     | 
| 
      
 127 
     | 
    
         
            +
                # @example
         
     | 
| 
      
 128 
     | 
    
         
            +
                #   [1] pry(main)> hist --show 46894
         
     | 
| 
      
 129 
     | 
    
         
            +
                #   46894: hist --replay 46675..46677
         
     | 
| 
      
 130 
     | 
    
         
            +
                #   [2] pry(main)> hist --show 46675..46677
         
     | 
| 
      
 131 
     | 
    
         
            +
                #   46675: 1+1
         
     | 
| 
      
 132 
     | 
    
         
            +
                #   46676: a = 100
         
     | 
| 
      
 133 
     | 
    
         
            +
                #   46677: hist --tail
         
     | 
| 
      
 134 
     | 
    
         
            +
                #   [3] pry(main)> hist --replay 46894
         
     | 
| 
      
 135 
     | 
    
         
            +
                #   Error: Replay index 46894 points out to another replay call: `hist -r 46675..46677`
         
     | 
| 
      
 136 
     | 
    
         
            +
                #   [4] pry(main)>
         
     | 
| 
      
 137 
     | 
    
         
            +
                #
         
     | 
| 
      
 138 
     | 
    
         
            +
                # @raise [Pry::CommandError] If +replay_sequence+ contains another
         
     | 
| 
      
 139 
     | 
    
         
            +
                #   "hist --replay" call
         
     | 
| 
      
 140 
     | 
    
         
            +
                # @param [String] replay_sequence The sequence of commands to be replayed
         
     | 
| 
      
 141 
     | 
    
         
            +
                #   (per saltum)
         
     | 
| 
      
 142 
     | 
    
         
            +
                # @return [Boolean] `false` if +replay_sequence+ does not contain another
         
     | 
| 
      
 143 
     | 
    
         
            +
                #   "hist --replay" call
         
     | 
| 
      
 144 
     | 
    
         
            +
                def check_for_juxtaposed_replay(replay_sequence)
         
     | 
| 
      
 145 
     | 
    
         
            +
                  if replay_sequence =~ /\Ahist(?:ory)?\b/
         
     | 
| 
      
 146 
     | 
    
         
            +
                    # Create *fresh* instance of Options for parsing of "hist" command.
         
     | 
| 
      
 147 
     | 
    
         
            +
                    _slop = self.slop
         
     | 
| 
      
 148 
     | 
    
         
            +
                    _slop.parse replay_sequence.split(' ')[1..-1]
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
                    if _slop.present?(:r)
         
     | 
| 
      
 151 
     | 
    
         
            +
                      replay_sequence = replay_sequence.split("\n").join('; ')
         
     | 
| 
      
 152 
     | 
    
         
            +
                      index = opts[:r]
         
     | 
| 
      
 153 
     | 
    
         
            +
                      index = index.min if index.min == index.max || index.max.nil?
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
      
 155 
     | 
    
         
            +
                      raise CommandError, "Replay index #{ index } points out to another replay call: `#{ replay_sequence }`"
         
     | 
| 
      
 156 
     | 
    
         
            +
                    end
         
     | 
| 
      
 157 
     | 
    
         
            +
                  else
         
     | 
| 
      
 158 
     | 
    
         
            +
                    false
         
     | 
| 
      
 159 
     | 
    
         
            +
                  end
         
     | 
| 
      
 160 
     | 
    
         
            +
                end
         
     | 
| 
      
 161 
     | 
    
         
            +
             
     | 
| 
      
 162 
     | 
    
         
            +
                # Finds history depending on the given switch.
         
     | 
| 
      
 163 
     | 
    
         
            +
                #
         
     | 
| 
      
 164 
     | 
    
         
            +
                # @return [Pry::Code] if it finds `--all` (or `-a`) switch, returns all
         
     | 
| 
      
 165 
     | 
    
         
            +
                #   entries in history. Without the switch returns only the entries from the
         
     | 
| 
      
 166 
     | 
    
         
            +
                #   current Pry session.
         
     | 
| 
      
 167 
     | 
    
         
            +
                def find_history
         
     | 
| 
      
 168 
     | 
    
         
            +
                  h = if opts.present?(:all)
         
     | 
| 
      
 169 
     | 
    
         
            +
                        Pry.history.to_a
         
     | 
| 
      
 170 
     | 
    
         
            +
                      else
         
     | 
| 
      
 171 
     | 
    
         
            +
                        Pry.history.to_a.last(Pry.history.session_line_count)
         
     | 
| 
      
 172 
     | 
    
         
            +
                      end
         
     | 
| 
      
 173 
     | 
    
         
            +
                  # The last value in history will be the 'hist' command itself.
         
     | 
| 
      
 174 
     | 
    
         
            +
                  Pry::Code(h[0..-2])
         
     | 
| 
      
 175 
     | 
    
         
            +
                end
         
     | 
| 
      
 176 
     | 
    
         
            +
              end
         
     | 
| 
      
 177 
     | 
    
         
            +
             
     | 
| 
      
 178 
     | 
    
         
            +
              Pry::Commands.add_command(Pry::Command::Hist)
         
     | 
| 
      
 179 
     | 
    
         
            +
              Pry::Commands.alias_command 'history', 'hist'
         
     | 
| 
      
 180 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,22 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Pry
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Command::ImportSet < Pry::ClassCommand
         
     | 
| 
      
 3 
     | 
    
         
            +
                match 'import-set'
         
     | 
| 
      
 4 
     | 
    
         
            +
                group 'Commands'
         
     | 
| 
      
 5 
     | 
    
         
            +
                # TODO: Provide a better description with examples and a general conception
         
     | 
| 
      
 6 
     | 
    
         
            +
                # of this command.
         
     | 
| 
      
 7 
     | 
    
         
            +
                description 'Import a Pry command set.'
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                banner <<-'BANNER'
         
     | 
| 
      
 10 
     | 
    
         
            +
                  Import a Pry command set.
         
     | 
| 
      
 11 
     | 
    
         
            +
                BANNER
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                def process(command_set_name)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  raise CommandError, "Provide a command set name" if command_set.nil?
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  set = target.eval(arg_string)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  _pry_.commands.import set
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              Pry::Commands.add_command(Pry::Command::ImportSet)
         
     | 
| 
      
 22 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,53 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Pry
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Command::InstallCommand < Pry::ClassCommand
         
     | 
| 
      
 3 
     | 
    
         
            +
                match 'install-command'
         
     | 
| 
      
 4 
     | 
    
         
            +
                group 'Commands'
         
     | 
| 
      
 5 
     | 
    
         
            +
                description 'Install a disabled command.'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                banner <<-'BANNER'
         
     | 
| 
      
 8 
     | 
    
         
            +
                  Usage: install-command COMMAND
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                  Installs the gems necessary to run the given COMMAND. You will generally not
         
     | 
| 
      
 11 
     | 
    
         
            +
                  need to run this unless told to by an error message.
         
     | 
| 
      
 12 
     | 
    
         
            +
                BANNER
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                def process(name)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  require 'rubygems/dependency_installer' unless defined? Gem::DependencyInstaller
         
     | 
| 
      
 16 
     | 
    
         
            +
                  command = find_command(name)
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                  unless command
         
     | 
| 
      
 19 
     | 
    
         
            +
                    output.puts "Command #{ text.green(name) } is not found"
         
     | 
| 
      
 20 
     | 
    
         
            +
                    return
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                  if command_dependencies_met?(command.options)
         
     | 
| 
      
 24 
     | 
    
         
            +
                    output.puts "Dependencies for #{ text.green(name) } are met. Nothing to do"
         
     | 
| 
      
 25 
     | 
    
         
            +
                    return
         
     | 
| 
      
 26 
     | 
    
         
            +
                  end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                  output.puts "Attempting to install #{ text.green(name) } command..."
         
     | 
| 
      
 29 
     | 
    
         
            +
                  gems_to_install = Array(command.options[:requires_gem])
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                  gems_to_install.each do |g|
         
     | 
| 
      
 32 
     | 
    
         
            +
                    next if Rubygem.installed?(g)
         
     | 
| 
      
 33 
     | 
    
         
            +
                    output.puts "Installing #{ text.green(g) } gem..."
         
     | 
| 
      
 34 
     | 
    
         
            +
                    Rubygem.install(g)
         
     | 
| 
      
 35 
     | 
    
         
            +
                  end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                  gems_to_install.each do |g|
         
     | 
| 
      
 38 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 39 
     | 
    
         
            +
                      require g
         
     | 
| 
      
 40 
     | 
    
         
            +
                    rescue LoadError
         
     | 
| 
      
 41 
     | 
    
         
            +
                      fail_msg = "Required gem #{ text.green(g) } installed but not found."
         
     | 
| 
      
 42 
     | 
    
         
            +
                      fail_msg += " Aborting command installation\n"
         
     | 
| 
      
 43 
     | 
    
         
            +
                      fail_msg += 'Tips: 1. Check your PATH; 2. Run `bundle update`'
         
     | 
| 
      
 44 
     | 
    
         
            +
                      raise CommandError, fail_msg
         
     | 
| 
      
 45 
     | 
    
         
            +
                    end
         
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                  output.puts "Installation of #{ text.green(name) } successful! Type `help #{name}` for information"
         
     | 
| 
      
 49 
     | 
    
         
            +
                end
         
     | 
| 
      
 50 
     | 
    
         
            +
              end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
              Pry::Commands.add_command(Pry::Command::InstallCommand)
         
     | 
| 
      
 53 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,29 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Pry
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Command::JumpTo < Pry::ClassCommand
         
     | 
| 
      
 3 
     | 
    
         
            +
                match 'jump-to'
         
     | 
| 
      
 4 
     | 
    
         
            +
                group 'Navigating Pry'
         
     | 
| 
      
 5 
     | 
    
         
            +
                description 'Jump to a binding further up the stack.'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                banner <<-'BANNER'
         
     | 
| 
      
 8 
     | 
    
         
            +
                  Jump to a binding further up the stack, popping all bindings below.
         
     | 
| 
      
 9 
     | 
    
         
            +
                BANNER
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                def process(break_level)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  break_level = break_level.to_i
         
     | 
| 
      
 13 
     | 
    
         
            +
                  nesting_level = _pry_.binding_stack.size - 1
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                  case break_level
         
     | 
| 
      
 16 
     | 
    
         
            +
                  when nesting_level
         
     | 
| 
      
 17 
     | 
    
         
            +
                    output.puts "Already at nesting level #{nesting_level}"
         
     | 
| 
      
 18 
     | 
    
         
            +
                  when (0...nesting_level)
         
     | 
| 
      
 19 
     | 
    
         
            +
                    _pry_.binding_stack.slice!(break_level + 1, _pry_.binding_stack.size)
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                  else
         
     | 
| 
      
 22 
     | 
    
         
            +
                    max_nest_level = nesting_level - 1
         
     | 
| 
      
 23 
     | 
    
         
            +
                    output.puts "Invalid nest level. Must be between 0 and #{max_nest_level}. Got #{break_level}."
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              Pry::Commands.add_command(Pry::Command::JumpTo)
         
     | 
| 
      
 29 
     | 
    
         
            +
            end
         
     |