mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
a9a49ee8a3
This fixes #957 and should make object path resolution more predictable in general. Instead of splitting the path on "/" before doing any parsing, we use `StringScanner` and `complete_expression?` to scan through the string looking for complete slash-delimited Ruby expressions. It also turned out that separating the code for handling "-" from the path-resolution code simplified things a lot. It doesn't really make sense for "-" to be in there anyway, since paths like "foo/-/bar" don't mean anything.
41 lines
1.1 KiB
Ruby
41 lines
1.1 KiB
Ruby
class Pry
|
|
class Command::Cd < Pry::ClassCommand
|
|
match 'cd'
|
|
group 'Context'
|
|
description 'Move into a new context (object or scope).'
|
|
|
|
banner <<-'BANNER'
|
|
Usage: cd [OPTIONS] [--help]
|
|
|
|
Move into new context (object or scope). As in UNIX shells use `cd ..` to go
|
|
back, `cd /` to return to Pry top-level and `cd -` to toggle between last two
|
|
scopes. Complex syntax (e.g `cd ../@x/@y`) also supported.
|
|
|
|
cd @x
|
|
cd ..
|
|
cd /
|
|
cd -
|
|
|
|
https://github.com/pry/pry/wiki/State-navigation#wiki-Changing_scope
|
|
BANNER
|
|
|
|
def process
|
|
state.old_stack ||= []
|
|
|
|
if arg_string.strip == "-"
|
|
unless state.old_stack.empty?
|
|
_pry_.binding_stack, state.old_stack = state.old_stack, _pry_.binding_stack
|
|
end
|
|
else
|
|
stack = ObjectPath.new(arg_string, _pry_.binding_stack).resolve
|
|
|
|
if stack && stack != _pry_.binding_stack
|
|
state.old_stack = _pry_.binding_stack
|
|
_pry_.binding_stack = stack
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
Pry::Commands.add_command(Pry::Command::Cd)
|
|
end
|