pry 0.12.2-java → 0.13.0-java
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 +5 -5
- data/CHANGELOG.md +110 -1
- data/LICENSE +1 -1
- data/README.md +331 -269
- data/bin/pry +5 -0
- data/lib/pry.rb +133 -119
- data/lib/pry/basic_object.rb +8 -4
- data/lib/pry/block_command.rb +22 -0
- data/lib/pry/class_command.rb +194 -0
- data/lib/pry/cli.rb +40 -31
- data/lib/pry/code.rb +39 -27
- data/lib/pry/code/code_file.rb +28 -24
- data/lib/pry/code/code_range.rb +4 -2
- data/lib/pry/code/loc.rb +15 -8
- data/lib/pry/code_object.rb +40 -38
- data/lib/pry/color_printer.rb +47 -46
- data/lib/pry/command.rb +166 -369
- data/lib/pry/command_set.rb +76 -73
- data/lib/pry/command_state.rb +31 -0
- data/lib/pry/commands/amend_line.rb +86 -81
- data/lib/pry/commands/bang.rb +18 -14
- data/lib/pry/commands/bang_pry.rb +15 -11
- data/lib/pry/commands/cat.rb +61 -54
- data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
- data/lib/pry/commands/cat/exception_formatter.rb +71 -60
- data/lib/pry/commands/cat/file_formatter.rb +55 -49
- data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
- data/lib/pry/commands/cd.rb +40 -35
- data/lib/pry/commands/change_inspector.rb +29 -22
- data/lib/pry/commands/change_prompt.rb +44 -39
- data/lib/pry/commands/clear_screen.rb +16 -10
- data/lib/pry/commands/code_collector.rb +148 -133
- data/lib/pry/commands/disable_pry.rb +23 -19
- data/lib/pry/commands/easter_eggs.rb +19 -30
- data/lib/pry/commands/edit.rb +184 -161
- 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/exit.rb +39 -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 -160
- data/lib/pry/commands/fix_indent.rb +16 -12
- data/lib/pry/commands/help.rb +140 -133
- data/lib/pry/commands/hist.rb +151 -150
- data/lib/pry/commands/import_set.rb +20 -16
- data/lib/pry/commands/jump_to.rb +25 -21
- data/lib/pry/commands/list_inspectors.rb +35 -28
- data/lib/pry/commands/ls.rb +124 -102
- data/lib/pry/commands/ls/constants.rb +59 -42
- data/lib/pry/commands/ls/formatter.rb +50 -46
- data/lib/pry/commands/ls/globals.rb +38 -34
- data/lib/pry/commands/ls/grep.rb +17 -13
- data/lib/pry/commands/ls/instance_vars.rb +29 -27
- 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 -22
- data/lib/pry/commands/ls/local_vars.rb +38 -28
- data/lib/pry/commands/ls/ls_entity.rb +47 -51
- data/lib/pry/commands/ls/methods.rb +44 -43
- data/lib/pry/commands/ls/methods_helper.rb +46 -42
- data/lib/pry/commands/ls/self_methods.rb +23 -22
- data/lib/pry/commands/nesting.rb +21 -17
- data/lib/pry/commands/play.rb +93 -82
- data/lib/pry/commands/pry_backtrace.rb +24 -17
- data/lib/pry/commands/pry_version.rb +15 -11
- data/lib/pry/commands/raise_up.rb +27 -22
- data/lib/pry/commands/reload_code.rb +60 -48
- data/lib/pry/commands/reset.rb +16 -12
- data/lib/pry/commands/ri.rb +55 -45
- data/lib/pry/commands/save_file.rb +45 -43
- data/lib/pry/commands/shell_command.rb +51 -51
- data/lib/pry/commands/shell_mode.rb +21 -17
- data/lib/pry/commands/show_doc.rb +81 -68
- data/lib/pry/commands/show_info.rb +189 -171
- data/lib/pry/commands/show_input.rb +16 -11
- data/lib/pry/commands/show_source.rb +109 -45
- 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.rb +89 -86
- data/lib/pry/commands/watch_expression/expression.rb +32 -27
- data/lib/pry/commands/whereami.rb +156 -148
- data/lib/pry/commands/wtf.rb +75 -50
- data/lib/pry/config.rb +311 -25
- 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/control_d_handler.rb +28 -0
- data/lib/pry/core_extensions.rb +9 -7
- data/lib/pry/editor.rb +48 -21
- data/lib/pry/env.rb +18 -0
- data/lib/pry/exception_handler.rb +43 -0
- data/lib/pry/exceptions.rb +13 -16
- data/lib/pry/forwardable.rb +5 -1
- data/lib/pry/helpers.rb +2 -0
- data/lib/pry/helpers/base_helpers.rb +68 -197
- data/lib/pry/helpers/command_helpers.rb +50 -61
- data/lib/pry/helpers/documentation_helpers.rb +20 -13
- data/lib/pry/helpers/options_helpers.rb +14 -7
- data/lib/pry/helpers/platform.rb +7 -5
- data/lib/pry/helpers/table.rb +33 -26
- data/lib/pry/helpers/text.rb +17 -14
- data/lib/pry/history.rb +48 -56
- data/lib/pry/hooks.rb +21 -12
- data/lib/pry/indent.rb +54 -50
- data/lib/pry/input_completer.rb +248 -230
- data/lib/pry/input_lock.rb +8 -9
- data/lib/pry/inspector.rb +36 -24
- data/lib/pry/last_exception.rb +45 -45
- data/lib/pry/method.rb +141 -94
- data/lib/pry/method/disowned.rb +16 -4
- data/lib/pry/method/patcher.rb +12 -3
- data/lib/pry/method/weird_method_locator.rb +68 -44
- data/lib/pry/object_path.rb +33 -25
- data/lib/pry/output.rb +121 -35
- data/lib/pry/pager.rb +41 -42
- data/lib/pry/plugins.rb +25 -8
- data/lib/pry/prompt.rb +123 -54
- data/lib/pry/pry_class.rb +61 -98
- data/lib/pry/pry_instance.rb +217 -215
- data/lib/pry/repl.rb +18 -22
- data/lib/pry/repl_file_loader.rb +27 -21
- data/lib/pry/ring.rb +11 -6
- data/lib/pry/slop.rb +574 -563
- data/lib/pry/slop/commands.rb +164 -169
- data/lib/pry/slop/option.rb +172 -168
- data/lib/pry/syntax_highlighter.rb +26 -0
- data/lib/pry/system_command_handler.rb +17 -0
- data/lib/pry/testable.rb +59 -61
- data/lib/pry/testable/evalable.rb +21 -12
- data/lib/pry/testable/mockable.rb +18 -10
- data/lib/pry/testable/pry_tester.rb +71 -56
- data/lib/pry/testable/utility.rb +29 -21
- data/lib/pry/testable/variables.rb +49 -43
- data/lib/pry/version.rb +3 -1
- data/lib/pry/warning.rb +27 -0
- data/lib/pry/wrapped_module.rb +51 -42
- data/lib/pry/wrapped_module/candidate.rb +21 -14
- metadata +31 -30
- data/lib/pry/commands.rb +0 -6
- 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/gem_readme.rb +0 -25
- data/lib/pry/commands/gem_search.rb +0 -40
- data/lib/pry/commands/gem_stats.rb +0 -83
- data/lib/pry/commands/gist.rb +0 -102
- data/lib/pry/commands/install_command.rb +0 -54
- data/lib/pry/config/behavior.rb +0 -255
- data/lib/pry/config/convenience.rb +0 -28
- data/lib/pry/config/default.rb +0 -159
- data/lib/pry/config/memoization.rb +0 -48
- data/lib/pry/platform.rb +0 -91
- data/lib/pry/rubygem.rb +0 -84
- data/lib/pry/terminal.rb +0 -91
@@ -1,19 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
4
|
+
class Command
|
5
|
+
class FixIndent < Pry::ClassCommand
|
6
|
+
match 'fix-indent'
|
7
|
+
group 'Input and Output'
|
5
8
|
|
6
|
-
|
9
|
+
description "Correct the indentation for contents of the input buffer"
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
banner <<-USAGE
|
12
|
+
Usage: fix-indent
|
13
|
+
USAGE
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
+
def process
|
16
|
+
indented_str = Pry::Indent.indent(eval_string)
|
17
|
+
pry_instance.eval_string = indented_str
|
18
|
+
end
|
15
19
|
end
|
16
|
-
end
|
17
20
|
|
18
|
-
|
21
|
+
Pry::Commands.add_command(Pry::Command::FixIndent)
|
22
|
+
end
|
19
23
|
end
|
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
|
-
"#{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,181 +1,182 @@
|
|
1
|
-
|
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
|
1
|
+
# frozen_string_literal: true
|
37
2
|
|
38
|
-
|
39
|
-
|
3
|
+
class Pry
|
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"
|
40
41
|
end
|
41
42
|
|
42
|
-
|
43
|
-
@history =
|
44
|
-
end
|
43
|
+
def process
|
44
|
+
@history = find_history
|
45
45
|
|
46
|
-
|
47
|
-
case
|
48
|
-
when opts.present?(:head)
|
49
|
-
@history.take_lines(1, opts[:head] || 10)
|
50
|
-
when opts.present?(:tail)
|
51
|
-
@history.take_lines(-(opts[:tail] || 10), opts[:tail] || 10)
|
52
|
-
when opts.present?(:show)
|
53
|
-
@history.between(opts[:show])
|
54
|
-
else
|
55
|
-
@history
|
56
|
-
end
|
46
|
+
@history = @history.between(opts[:show]) if opts.present?(:show)
|
57
47
|
|
58
|
-
|
59
|
-
@history = @history.select do |loc|
|
60
|
-
!command_set.valid_command?(loc.line)
|
61
|
-
end
|
62
|
-
end
|
48
|
+
@history = @history.grep(opts[:grep]) if opts.present?(:grep)
|
63
49
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
end
|
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
|
74
58
|
|
75
|
-
|
59
|
+
if opts.present?(:'exclude-pry')
|
60
|
+
@history = @history.reject do |loc|
|
61
|
+
command_set.valid_command?(loc.line)
|
62
|
+
end
|
63
|
+
end
|
76
64
|
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
80
74
|
end
|
81
75
|
|
82
|
-
|
83
|
-
@history.print_to_output(pager, true)
|
84
|
-
end
|
85
|
-
end
|
76
|
+
private
|
86
77
|
|
87
|
-
|
88
|
-
|
89
|
-
when Range
|
90
|
-
@history = @history.between(opts[:save])
|
78
|
+
def process_display
|
79
|
+
@history = @history.with_line_numbers unless opts.present?(:'no-numbers')
|
91
80
|
|
92
|
-
|
93
|
-
|
81
|
+
pry_instance.pager.open do |pager|
|
82
|
+
@history.print_to_output(pager, true)
|
94
83
|
end
|
95
|
-
|
96
|
-
file_name = File.expand_path(args.first)
|
97
|
-
when String
|
98
|
-
file_name = File.expand_path(opts[:save])
|
99
84
|
end
|
100
85
|
|
101
|
-
|
86
|
+
def process_save
|
87
|
+
case opts[:save]
|
88
|
+
when Range
|
89
|
+
@history = @history.between(opts[:save])
|
102
90
|
|
103
|
-
|
91
|
+
raise CommandError, "Must provide a file name." unless args.first
|
104
92
|
|
105
|
-
|
106
|
-
|
93
|
+
file_name = File.expand_path(args.first)
|
94
|
+
when String
|
95
|
+
file_name = File.expand_path(opts[:save])
|
96
|
+
end
|
107
97
|
|
108
|
-
|
109
|
-
Pry.history.clear
|
110
|
-
output.puts "History cleared."
|
111
|
-
end
|
98
|
+
output.puts "Saving history in #{file_name}..."
|
112
99
|
|
113
|
-
|
114
|
-
@history = @history.between(opts[:r])
|
115
|
-
replay_sequence = @history.raw
|
100
|
+
File.open(file_name, 'w') { |f| f.write(@history.raw) }
|
116
101
|
|
117
|
-
|
118
|
-
|
119
|
-
# further.
|
120
|
-
check_for_juxtaposed_replay(replay_sequence)
|
102
|
+
output.puts "History saved."
|
103
|
+
end
|
121
104
|
|
122
|
-
|
123
|
-
|
105
|
+
def process_clear
|
106
|
+
Pry.history.clear
|
107
|
+
output.puts "History cleared."
|
124
108
|
end
|
125
|
-
end
|
126
109
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
#
|
139
|
-
# @raise [Pry::CommandError] If +replay_sequence+ contains another
|
140
|
-
# "hist --replay" call
|
141
|
-
# @param [String] replay_sequence The sequence of commands to be replayed
|
142
|
-
# (per saltum)
|
143
|
-
# @return [Boolean] `false` if +replay_sequence+ does not contain another
|
144
|
-
# "hist --replay" call
|
145
|
-
def check_for_juxtaposed_replay(replay_sequence)
|
146
|
-
if replay_sequence =~ /\Ahist(?:ory)?\b/
|
147
|
-
# Create *fresh* instance of Options for parsing of "hist" command.
|
148
|
-
_slop = self.slop
|
149
|
-
_slop.parse replay_sequence.split(' ')[1..-1]
|
150
|
-
|
151
|
-
if _slop.present?(:r)
|
152
|
-
replay_sequence = replay_sequence.split("\n").join('; ')
|
153
|
-
index = opts[:r]
|
154
|
-
index = index.min if index.min == index.max || index.max.nil?
|
155
|
-
|
156
|
-
raise CommandError, "Replay index #{ index } points out to another replay call: `#{ replay_sequence }`"
|
110
|
+
def process_replay
|
111
|
+
@history = @history.between(opts[:r])
|
112
|
+
replay_sequence = @history.raw
|
113
|
+
|
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)
|
118
|
+
|
119
|
+
replay_sequence.lines.each do |line|
|
120
|
+
pry_instance.eval line, generated: true
|
157
121
|
end
|
158
|
-
else
|
159
|
-
false
|
160
122
|
end
|
161
|
-
end
|
162
123
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
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}`"
|
173
157
|
end
|
158
|
+
else
|
159
|
+
false
|
160
|
+
end
|
161
|
+
end
|
174
162
|
|
175
|
-
|
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
|
176
177
|
end
|
177
|
-
end
|
178
178
|
|
179
|
-
|
180
|
-
|
179
|
+
Pry::Commands.add_command(Pry::Command::Hist)
|
180
|
+
Pry::Commands.alias_command 'history', 'hist'
|
181
|
+
end
|
181
182
|
end
|