pry 0.10.3 → 0.14.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +439 -16
- data/LICENSE +1 -1
- data/README.md +362 -302
- data/bin/pry +4 -7
- data/lib/pry/basic_object.rb +10 -0
- data/lib/pry/block_command.rb +22 -0
- data/lib/pry/class_command.rb +194 -0
- data/lib/pry/cli.rb +84 -97
- data/lib/pry/code/code_file.rb +37 -26
- data/lib/pry/code/code_range.rb +7 -5
- data/lib/pry/code/loc.rb +26 -13
- data/lib/pry/code.rb +42 -31
- data/lib/pry/code_object.rb +53 -28
- data/lib/pry/color_printer.rb +46 -35
- data/lib/pry/command.rb +197 -369
- data/lib/pry/command_set.rb +89 -114
- data/lib/pry/command_state.rb +31 -0
- data/lib/pry/commands/amend_line.rb +86 -82
- data/lib/pry/commands/bang.rb +18 -14
- data/lib/pry/commands/bang_pry.rb +15 -11
- data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
- data/lib/pry/commands/cat/exception_formatter.rb +85 -72
- data/lib/pry/commands/cat/file_formatter.rb +56 -46
- data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
- data/lib/pry/commands/cat.rb +62 -54
- data/lib/pry/commands/cd.rb +40 -35
- data/lib/pry/commands/change_inspector.rb +29 -22
- data/lib/pry/commands/change_prompt.rb +48 -23
- data/lib/pry/commands/clear_screen.rb +20 -0
- data/lib/pry/commands/code_collector.rb +148 -131
- data/lib/pry/commands/disable_pry.rb +23 -19
- data/lib/pry/commands/easter_eggs.rb +23 -34
- data/lib/pry/commands/edit/exception_patcher.rb +21 -17
- data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
- data/lib/pry/commands/edit.rb +185 -157
- data/lib/pry/commands/exit.rb +40 -35
- data/lib/pry/commands/exit_all.rb +24 -20
- data/lib/pry/commands/exit_program.rb +20 -16
- data/lib/pry/commands/find_method.rb +168 -162
- data/lib/pry/commands/fix_indent.rb +16 -12
- data/lib/pry/commands/help.rb +140 -133
- data/lib/pry/commands/hist.rb +151 -149
- data/lib/pry/commands/import_set.rb +20 -15
- data/lib/pry/commands/jump_to.rb +25 -21
- data/lib/pry/commands/list_inspectors.rb +35 -28
- data/lib/pry/commands/ls/constants.rb +59 -31
- data/lib/pry/commands/ls/formatter.rb +42 -36
- data/lib/pry/commands/ls/globals.rb +38 -36
- data/lib/pry/commands/ls/grep.rb +17 -15
- data/lib/pry/commands/ls/instance_vars.rb +29 -28
- data/lib/pry/commands/ls/interrogatable.rb +18 -12
- data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
- data/lib/pry/commands/ls/local_names.rb +26 -24
- data/lib/pry/commands/ls/local_vars.rb +38 -30
- data/lib/pry/commands/ls/ls_entity.rb +47 -52
- data/lib/pry/commands/ls/methods.rb +49 -51
- data/lib/pry/commands/ls/methods_helper.rb +46 -42
- data/lib/pry/commands/ls/self_methods.rb +23 -21
- data/lib/pry/commands/ls.rb +124 -103
- data/lib/pry/commands/nesting.rb +21 -17
- data/lib/pry/commands/play.rb +92 -82
- data/lib/pry/commands/pry_backtrace.rb +22 -17
- data/lib/pry/commands/pry_version.rb +15 -11
- data/lib/pry/commands/raise_up.rb +33 -27
- data/lib/pry/commands/reload_code.rb +60 -48
- data/lib/pry/commands/reset.rb +16 -12
- data/lib/pry/commands/ri.rb +57 -42
- data/lib/pry/commands/save_file.rb +45 -43
- data/lib/pry/commands/shell_command.rb +56 -29
- data/lib/pry/commands/shell_mode.rb +22 -18
- data/lib/pry/commands/show_doc.rb +80 -70
- data/lib/pry/commands/show_info.rb +194 -155
- data/lib/pry/commands/show_input.rb +16 -11
- data/lib/pry/commands/show_source.rb +110 -42
- data/lib/pry/commands/stat.rb +35 -31
- data/lib/pry/commands/switch_to.rb +21 -15
- data/lib/pry/commands/toggle_color.rb +20 -16
- data/lib/pry/commands/watch_expression/expression.rb +32 -27
- data/lib/pry/commands/watch_expression.rb +89 -84
- data/lib/pry/commands/whereami.rb +156 -141
- data/lib/pry/commands/wtf.rb +78 -40
- data/lib/pry/config/attributable.rb +22 -0
- data/lib/pry/config/lazy_value.rb +29 -0
- data/lib/pry/config/memoized_value.rb +34 -0
- data/lib/pry/config/value.rb +24 -0
- data/lib/pry/config.rb +310 -20
- data/lib/pry/control_d_handler.rb +28 -0
- data/lib/pry/core_extensions.rb +22 -9
- data/lib/pry/editor.rb +56 -34
- data/lib/pry/env.rb +18 -0
- data/lib/pry/exception_handler.rb +43 -0
- data/lib/pry/exceptions.rb +13 -18
- data/lib/pry/forwardable.rb +27 -0
- data/lib/pry/helpers/base_helpers.rb +20 -62
- data/lib/pry/helpers/command_helpers.rb +52 -62
- data/lib/pry/helpers/documentation_helpers.rb +21 -12
- data/lib/pry/helpers/options_helpers.rb +15 -8
- data/lib/pry/helpers/platform.rb +55 -0
- data/lib/pry/helpers/table.rb +44 -32
- data/lib/pry/helpers/text.rb +96 -85
- data/lib/pry/helpers.rb +3 -0
- data/lib/pry/history.rb +81 -55
- data/lib/pry/hooks.rb +60 -110
- data/lib/pry/indent.rb +74 -68
- data/lib/pry/input_completer.rb +199 -158
- data/lib/pry/input_lock.rb +7 -10
- data/lib/pry/inspector.rb +36 -24
- data/lib/pry/last_exception.rb +45 -45
- data/lib/pry/method/disowned.rb +19 -5
- data/lib/pry/method/patcher.rb +14 -8
- data/lib/pry/method/weird_method_locator.rb +79 -45
- data/lib/pry/method.rb +178 -124
- data/lib/pry/object_path.rb +37 -28
- data/lib/pry/output.rb +102 -16
- data/lib/pry/pager.rb +187 -174
- data/lib/pry/prompt.rb +213 -25
- data/lib/pry/pry_class.rb +119 -98
- data/lib/pry/pry_instance.rb +261 -224
- data/lib/pry/repl.rb +83 -29
- data/lib/pry/repl_file_loader.rb +27 -22
- data/lib/pry/ring.rb +89 -0
- data/lib/pry/slop/LICENSE +20 -0
- data/lib/pry/slop/commands.rb +190 -0
- data/lib/pry/slop/option.rb +210 -0
- data/lib/pry/slop.rb +672 -0
- data/lib/pry/syntax_highlighter.rb +26 -0
- data/lib/pry/system_command_handler.rb +17 -0
- data/lib/pry/testable/evalable.rb +24 -0
- data/lib/pry/testable/mockable.rb +22 -0
- data/lib/pry/testable/pry_tester.rb +88 -0
- data/lib/pry/testable/utility.rb +34 -0
- data/lib/pry/testable/variables.rb +52 -0
- data/lib/pry/testable.rb +68 -0
- data/lib/pry/version.rb +3 -1
- data/lib/pry/warning.rb +20 -0
- data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +35 -32
- data/lib/pry/wrapped_module.rb +68 -63
- data/lib/pry.rb +133 -149
- metadata +58 -69
- data/lib/pry/commands/disabled_commands.rb +0 -2
- data/lib/pry/commands/gem_cd.rb +0 -26
- data/lib/pry/commands/gem_install.rb +0 -32
- data/lib/pry/commands/gem_list.rb +0 -33
- data/lib/pry/commands/gem_open.rb +0 -29
- data/lib/pry/commands/gist.rb +0 -101
- data/lib/pry/commands/install_command.rb +0 -53
- data/lib/pry/commands/list_prompts.rb +0 -35
- data/lib/pry/commands/simple_prompt.rb +0 -22
- data/lib/pry/commands.rb +0 -6
- data/lib/pry/config/behavior.rb +0 -139
- data/lib/pry/config/convenience.rb +0 -25
- data/lib/pry/config/default.rb +0 -161
- data/lib/pry/history_array.rb +0 -121
- data/lib/pry/plugins.rb +0 -103
- data/lib/pry/rbx_path.rb +0 -22
- data/lib/pry/rubygem.rb +0 -82
- data/lib/pry/terminal.rb +0 -79
- data/lib/pry/test/helper.rb +0 -170
data/lib/pry/commands/help.rb
CHANGED
@@ -1,164 +1,171 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
4
|
+
class Command
|
5
|
+
class Help < Pry::ClassCommand
|
6
|
+
match 'help'
|
7
|
+
group 'Help'
|
8
|
+
description 'Show a list of commands or information about a specific command.'
|
9
|
+
|
10
|
+
banner <<-'BANNER'
|
11
|
+
Usage: help [COMMAND]
|
12
|
+
|
13
|
+
With no arguments, help lists all the available commands along with their
|
14
|
+
descriptions. When given a command name as an argument, shows the help
|
15
|
+
for that command.
|
16
|
+
BANNER
|
17
|
+
|
18
|
+
# We only want to show commands that have descriptions, so that the
|
19
|
+
# easter eggs don't show up.
|
20
|
+
def visible_commands
|
21
|
+
visible = {}
|
22
|
+
commands.each do |key, command|
|
23
|
+
visible[key] = command if command.description && !command.description.empty?
|
24
|
+
end
|
25
|
+
visible
|
21
26
|
end
|
22
|
-
visible
|
23
|
-
end
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
# Get a hash of available commands grouped by the "group" name.
|
29
|
+
def command_groups
|
30
|
+
visible_commands.values.group_by(&:group)
|
31
|
+
end
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
def process
|
34
|
+
if args.empty?
|
35
|
+
display_index(command_groups)
|
36
|
+
else
|
37
|
+
display_search(args.first)
|
38
|
+
end
|
35
39
|
end
|
36
|
-
end
|
37
40
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
# Display the index view, with headings and short descriptions per command.
|
42
|
+
#
|
43
|
+
# @param [Hash<String, Array<Commands>>] groups
|
44
|
+
def display_index(groups)
|
45
|
+
help_text = []
|
43
46
|
|
44
|
-
|
45
|
-
|
47
|
+
sorted_group_names(groups).each do |group_name|
|
48
|
+
commands = sorted_commands(groups[group_name])
|
46
49
|
|
47
|
-
|
48
|
-
help_text << help_text_for_commands(group_name, commands)
|
50
|
+
help_text << help_text_for_commands(group_name, commands) if commands.any?
|
49
51
|
end
|
52
|
+
|
53
|
+
pry_instance.pager.page help_text.join("\n\n")
|
50
54
|
end
|
51
55
|
|
52
|
-
|
53
|
-
|
56
|
+
# Given a group name and an array of commands,
|
57
|
+
# return the help string for those commands.
|
58
|
+
#
|
59
|
+
# @param [String] name The group name.
|
60
|
+
# @param [Array<Pry::Command>] commands
|
61
|
+
# @return [String] The generated help string.
|
62
|
+
def help_text_for_commands(name, commands)
|
63
|
+
"#{bold(name.capitalize)}\n" + commands.map do |command|
|
64
|
+
" #{command.options[:listing].to_s.ljust(18)} " \
|
65
|
+
"#{command.description.capitalize}"
|
66
|
+
end.join("\n")
|
67
|
+
end
|
54
68
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
69
|
+
# @param [Hash] groups
|
70
|
+
# @return [Array<String>] An array of sorted group names.
|
71
|
+
def sorted_group_names(groups)
|
72
|
+
groups.keys.sort_by(&method(:group_sort_key))
|
73
|
+
end
|
66
74
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
75
|
+
# Sort an array of commands by their `listing` name.
|
76
|
+
#
|
77
|
+
# @param [Array<Pry::Command>] commands The commands to sort
|
78
|
+
# @return [Array<Pry::Command>] commands sorted by listing name.
|
79
|
+
def sorted_commands(commands)
|
80
|
+
commands.sort_by { |command| command.options[:listing].to_s }
|
81
|
+
end
|
72
82
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
83
|
+
# Display help for an individual command or group.
|
84
|
+
#
|
85
|
+
# @param [String] search The string to search for.
|
86
|
+
def display_search(search)
|
87
|
+
if (command = command_set.find_command_for_help(search))
|
88
|
+
display_command(command)
|
89
|
+
else
|
90
|
+
display_filtered_search_results(search)
|
91
|
+
end
|
92
|
+
end
|
80
93
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
94
|
+
# Display help for a searched item, filtered first by group
|
95
|
+
# and if that fails, filtered by command name.
|
96
|
+
#
|
97
|
+
# @param [String] search The string to search for.
|
98
|
+
def display_filtered_search_results(search)
|
99
|
+
groups = search_hash(search, command_groups)
|
100
|
+
|
101
|
+
if !groups.empty?
|
102
|
+
display_index(groups)
|
103
|
+
else
|
104
|
+
display_filtered_commands(search)
|
105
|
+
end
|
89
106
|
end
|
90
|
-
end
|
91
107
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
108
|
+
# Display help for a searched item, filtered by group
|
109
|
+
#
|
110
|
+
# @param [String] search The string to search for.
|
111
|
+
def display_filtered_commands(search)
|
112
|
+
filtered = search_hash(search, visible_commands)
|
113
|
+
raise CommandError, "No help found for '#{args.first}'" if filtered.empty?
|
114
|
+
|
115
|
+
if filtered.size == 1
|
116
|
+
display_command(filtered.values.first)
|
117
|
+
else
|
118
|
+
display_index("'#{search}' commands" => filtered.values)
|
119
|
+
end
|
103
120
|
end
|
104
|
-
end
|
105
121
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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})
|
122
|
+
# Display help for an individual command.
|
123
|
+
#
|
124
|
+
# @param [Pry::Command] command
|
125
|
+
def display_command(command)
|
126
|
+
pry_instance.pager.page command.new.help
|
117
127
|
end
|
118
|
-
end
|
119
128
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
129
|
+
# Find a subset of a hash that matches the user's search term.
|
130
|
+
#
|
131
|
+
# If there's an exact match a Hash of one element will be returned,
|
132
|
+
# otherwise a sub-Hash with every key that matches the search will
|
133
|
+
# be returned.
|
134
|
+
#
|
135
|
+
# @param [String] search the search term
|
136
|
+
# @param [Hash] hash the hash to search
|
137
|
+
def search_hash(search, hash)
|
138
|
+
matching = {}
|
139
|
+
|
140
|
+
hash.each_pair do |key, value|
|
141
|
+
next unless key.is_a?(String)
|
142
|
+
return { key => value } if normalize(key) == normalize(search)
|
143
|
+
next unless normalize(key).start_with?(normalize(search))
|
126
144
|
|
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
145
|
matching[key] = value
|
144
146
|
end
|
147
|
+
|
148
|
+
matching
|
145
149
|
end
|
146
150
|
|
147
|
-
|
148
|
-
|
151
|
+
# Clean search terms to make it easier to search group names
|
152
|
+
#
|
153
|
+
# @param [String] key
|
154
|
+
# @return [String]
|
155
|
+
def normalize(key)
|
156
|
+
key.downcase.gsub(/pry\W+/, '')
|
157
|
+
end
|
149
158
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
159
|
+
def group_sort_key(group_name)
|
160
|
+
[
|
161
|
+
%w[
|
162
|
+
Help Context Editing Introspection Input_and_output Navigating_pry
|
163
|
+
Gems Basic Commands
|
164
|
+
].index(group_name.tr(' ', '_')) || 99, group_name
|
165
|
+
]
|
166
|
+
end
|
156
167
|
end
|
157
168
|
|
158
|
-
|
159
|
-
[%w(Help Context Editing Introspection Input_and_output Navigating_pry Gems Basic Commands).index(group_name.gsub(' ', '_')) || 99, group_name]
|
160
|
-
end
|
169
|
+
Pry::Commands.add_command(Pry::Command::Help)
|
161
170
|
end
|
162
|
-
|
163
|
-
Pry::Commands.add_command(Pry::Command::Help)
|
164
171
|
end
|
data/lib/pry/commands/hist.rb
CHANGED
@@ -1,180 +1,182 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
opt
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
4
|
+
class Command
|
5
|
+
class Hist < Pry::ClassCommand
|
6
|
+
match 'hist'
|
7
|
+
group 'Editing'
|
8
|
+
description 'Show and replay Readline history.'
|
9
|
+
|
10
|
+
banner <<-'BANNER'
|
11
|
+
Usage: hist [--head|--tail]
|
12
|
+
hist --all
|
13
|
+
hist --head N
|
14
|
+
hist --tail N
|
15
|
+
hist --show START..END
|
16
|
+
hist --grep PATTERN
|
17
|
+
hist --clear
|
18
|
+
hist --replay START..END
|
19
|
+
hist --save [START..END] FILE
|
20
|
+
Aliases: history
|
21
|
+
|
22
|
+
Show and replay Readline history.
|
23
|
+
BANNER
|
24
|
+
|
25
|
+
def options(opt)
|
26
|
+
opt.on :a, :all, "Display all history"
|
27
|
+
opt.on :H, :head, "Display the first N items",
|
28
|
+
optional_argument: true, as: Integer
|
29
|
+
opt.on :T, :tail, "Display the last N items",
|
30
|
+
optional_argument: true, as: Integer
|
31
|
+
opt.on :s, :show, "Show the given range of lines",
|
32
|
+
optional_argument: true, as: Range
|
33
|
+
opt.on :G, :grep, "Show lines matching the given pattern",
|
34
|
+
argument: true, as: String
|
35
|
+
opt.on :c, :clear, "Clear the current session's history"
|
36
|
+
opt.on :r, :replay, "Replay a line or range of lines",
|
37
|
+
argument: true, as: Range
|
38
|
+
opt.on :save, "Save history to a file", argument: true, as: Range
|
39
|
+
opt.on :e, :'exclude-pry', "Exclude Pry commands from the history"
|
40
|
+
opt.on :n, :'no-numbers', "Omit line numbers"
|
41
|
+
end
|
34
42
|
|
35
|
-
|
36
|
-
|
43
|
+
def process
|
44
|
+
@history = find_history
|
37
45
|
|
38
|
-
|
39
|
-
@history = @history.between(opts[:show])
|
40
|
-
end
|
46
|
+
@history = @history.between(opts[:show]) if opts.present?(:show)
|
41
47
|
|
42
|
-
|
43
|
-
@history = @history.grep(opts[:grep])
|
44
|
-
end
|
48
|
+
@history = @history.grep(opts[:grep]) if opts.present?(:grep)
|
45
49
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
@history =
|
51
|
+
if opts.present?(:head)
|
52
|
+
@history.take_lines(1, opts[:head] || 10)
|
53
|
+
elsif opts.present?(:tail)
|
54
|
+
@history.take_lines(-(opts[:tail] || 10), opts[:tail] || 10)
|
55
|
+
else
|
56
|
+
@history
|
57
|
+
end
|
58
|
+
|
59
|
+
if opts.present?(:'exclude-pry')
|
60
|
+
@history = @history.reject do |loc|
|
61
|
+
command_set.valid_command?(loc.line)
|
62
|
+
end
|
55
63
|
end
|
56
64
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
65
|
+
if opts.present?(:save)
|
66
|
+
process_save
|
67
|
+
elsif opts.present?(:clear)
|
68
|
+
process_clear
|
69
|
+
elsif opts.present?(:replay)
|
70
|
+
process_replay
|
71
|
+
else
|
72
|
+
process_display
|
73
|
+
end
|
61
74
|
end
|
62
75
|
|
63
|
-
|
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
|
76
|
+
private
|
73
77
|
|
74
|
-
|
78
|
+
def process_display
|
79
|
+
@history = @history.with_line_numbers unless opts.present?(:'no-numbers')
|
75
80
|
|
76
|
-
|
77
|
-
|
78
|
-
|
81
|
+
pry_instance.pager.open do |pager|
|
82
|
+
@history.print_to_output(pager, true)
|
83
|
+
end
|
79
84
|
end
|
80
85
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
86
|
+
def process_save
|
87
|
+
case opts[:save]
|
88
|
+
when Range
|
89
|
+
@history = @history.between(opts[:save])
|
85
90
|
|
86
|
-
|
87
|
-
case opts[:save]
|
88
|
-
when Range
|
89
|
-
@history = @history.between(opts[:save])
|
91
|
+
raise CommandError, "Must provide a file name." unless args.first
|
90
92
|
|
91
|
-
|
92
|
-
|
93
|
+
file_name = File.expand_path(args.first)
|
94
|
+
when String
|
95
|
+
file_name = File.expand_path(opts[:save])
|
93
96
|
end
|
94
97
|
|
95
|
-
|
96
|
-
when String
|
97
|
-
file_name = File.expand_path(opts[:save])
|
98
|
-
end
|
99
|
-
|
100
|
-
output.puts "Saving history in #{file_name}..."
|
98
|
+
output.puts "Saving history in #{file_name}..."
|
101
99
|
|
102
|
-
|
100
|
+
File.open(file_name, 'w') { |f| f.write(@history.raw) }
|
103
101
|
|
104
|
-
|
105
|
-
|
102
|
+
output.puts "History saved."
|
103
|
+
end
|
106
104
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
105
|
+
def process_clear
|
106
|
+
Pry.history.clear
|
107
|
+
output.puts "History cleared."
|
108
|
+
end
|
111
109
|
|
112
|
-
|
113
|
-
|
114
|
-
|
110
|
+
def process_replay
|
111
|
+
@history = @history.between(opts[:r])
|
112
|
+
replay_sequence = @history.raw
|
115
113
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
114
|
+
# If we met follow-up "hist" call, check for the "--replay" option
|
115
|
+
# presence. If "hist" command is called with other options, proceed
|
116
|
+
# further.
|
117
|
+
check_for_juxtaposed_replay(replay_sequence)
|
120
118
|
|
121
|
-
|
122
|
-
|
119
|
+
replay_sequence.lines.each do |line|
|
120
|
+
pry_instance.eval line, generated: true
|
121
|
+
end
|
123
122
|
end
|
124
|
-
end
|
125
123
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
124
|
+
# Checks +replay_sequence+ for the presence of neighboring replay calls.
|
125
|
+
# @example
|
126
|
+
# [1] pry(main)> hist --show 46894
|
127
|
+
# 46894: hist --replay 46675..46677
|
128
|
+
# [2] pry(main)> hist --show 46675..46677
|
129
|
+
# 46675: 1+1
|
130
|
+
# 46676: a = 100
|
131
|
+
# 46677: hist --tail
|
132
|
+
# [3] pry(main)> hist --replay 46894
|
133
|
+
# Error: Replay index 46894 points out to another replay call:
|
134
|
+
# `hist -r 46675..46677`
|
135
|
+
# [4] pry(main)>
|
136
|
+
#
|
137
|
+
# @raise [Pry::CommandError] If +replay_sequence+ contains another
|
138
|
+
# "hist --replay" call
|
139
|
+
# @param [String] replay_sequence The sequence of commands to be replayed
|
140
|
+
# (per saltum)
|
141
|
+
# @return [Boolean] `false` if +replay_sequence+ does not contain another
|
142
|
+
# "hist --replay" call
|
143
|
+
def check_for_juxtaposed_replay(replay_sequence)
|
144
|
+
if replay_sequence =~ /\Ahist(?:ory)?\b/
|
145
|
+
# Create *fresh* instance of Options for parsing of "hist" command.
|
146
|
+
slop_instance = slop
|
147
|
+
slop_instance.parse(replay_sequence.split(' ')[1..-1])
|
148
|
+
|
149
|
+
if slop_instance.present?(:r)
|
150
|
+
replay_sequence = replay_sequence.split("\n").join('; ')
|
151
|
+
index = opts[:r]
|
152
|
+
index = index.min if index.min == index.max || index.max.nil?
|
153
|
+
|
154
|
+
raise CommandError,
|
155
|
+
"Replay index #{index} points out to another replay call: " \
|
156
|
+
"`#{replay_sequence}`"
|
157
|
+
end
|
158
|
+
else
|
159
|
+
false
|
156
160
|
end
|
157
|
-
else
|
158
|
-
false
|
159
161
|
end
|
160
|
-
end
|
161
162
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
163
|
+
# Finds history depending on the given switch.
|
164
|
+
#
|
165
|
+
# @return [Pry::Code] if it finds `--all` (or `-a`) switch, returns all
|
166
|
+
# entries in history. Without the switch returns only the entries from the
|
167
|
+
# current Pry session.
|
168
|
+
def find_history
|
169
|
+
h = if opts.present?(:all)
|
170
|
+
Pry.history.to_a
|
171
|
+
else
|
172
|
+
Pry.history.to_a.last(Pry.history.session_line_count)
|
173
|
+
end
|
174
|
+
|
175
|
+
Pry::Code(Pry.history.filter(h[0..-2]))
|
176
|
+
end
|
175
177
|
end
|
176
|
-
end
|
177
178
|
|
178
|
-
|
179
|
-
|
179
|
+
Pry::Commands.add_command(Pry::Command::Hist)
|
180
|
+
Pry::Commands.alias_command 'history', 'hist'
|
181
|
+
end
|
180
182
|
end
|