/
commands.rb
35 lines (31 loc) · 1.2 KB
/
commands.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module PryCommandSetRegistry
desc = "Commands for interacting with the Pry command set registry"
# Default commands for interacting with PryCommandSetRegistry imported into
# Pry.
Commands = CommandSet.new("PryCommandSetRegistry", desc, :group => "Command Set Registry") do
command("import-set", "Import a Pry command set") do |command_set_name|
raise Pry::CommandError, "Provide a command set name" if command_set_name.nil?
begin
set = target.eval(command_set_name)
rescue NameError
set = PryCommandSetRegistry.command_set(command_set_name)
::Kernel.raise if set.nil?
end
_pry_.commands.import(set)
end
command("list-sets", "List registered command sets") do
_pry_.output.puts "Registered Command Sets:"
_pry_.output.puts format_command_set_listing(PryCommandSetRegistry.command_sets)
end
helpers do
def format_command_set_listing(command_sets)
return "" if command_sets.none?
max_len = command_sets.keys.max_by(&:length).length
sets = command_sets.map do |set_name, set|
" #{set_name.ljust(max_len)} - #{set.description}"
end
sets.join("\n")
end
end
end
end