Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor exit command #835

Merged
merged 3 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,23 @@ Hello World

The following commands are available on IRB. You can get the same output from the `show_cmds` command.

```
Workspace
cwws Show the current workspace.
chws Change the current workspace to an object.
workspaces Show workspaces.
pushws Push an object to the workspace stack.
popws Pop a workspace from the workspace stack.

```txt
IRB
exit Exit the current irb session.
irb_load Load a Ruby file.
irb_require Require a Ruby file.
source Loads a given file in the current session.
irb_info Show information about IRB.
show_cmds List all available commands and their description.
history Shows the input history. `-g [query]` or `-G [query]` allows you to filter the output.

Workspace
cwws Show the current workspace.
chws Change the current workspace to an object.
workspaces Show workspaces.
pushws Push an object to the workspace stack.
popws Pop a workspace from the workspace stack.

Multi-irb (DEPRECATED)
irb Start a child IRB.
jobs List of current sessions.
Expand Down Expand Up @@ -153,6 +154,10 @@ Context
ls Show methods, constants, and variables. `-g [query]` or `-G [query]` allows you to filter out the output.
show_source Show the source code of a given method or constant.
whereami Show the source code around binding.irb again.

Aliases
$ Alias for `show_source`
@ Alias for `whereami`
```

## Debugging with IRB
Expand Down
4 changes: 2 additions & 2 deletions lib/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,8 @@ def IRB.start(ap_path = nil)
end

# Quits irb
def IRB.irb_exit(irb, ret)
throw :IRB_EXIT, ret
def IRB.irb_exit(*)
throw :IRB_EXIT
end

# Aborts then interrupts irb.
Expand Down
22 changes: 22 additions & 0 deletions lib/irb/cmd/exit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require_relative "nop"

module IRB
# :stopdoc:

module ExtendCommand
class Exit < Nop
category "IRB"
description "Exit the current irb session."

def execute(*)
IRB.irb_exit
rescue UncaughtThrowError
Kernel.exit
end
end
end

# :startdoc:
end
8 changes: 0 additions & 8 deletions lib/irb/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -573,14 +573,6 @@ def inspect_last_value # :nodoc:
@inspect_method.inspect_value(@last_value)
end

alias __exit__ exit
# Exits the current session, see IRB.irb_exit
def exit(ret = 0)
IRB.irb_exit(@irb, ret)
rescue UncaughtThrowError
super
end

NOPRINTING_IVARS = ["@last_value"] # :nodoc:
NO_INSPECTING_IVARS = ["@irb", "@io"] # :nodoc:
IDNAME_IVARS = ["@prompt_mode"] # :nodoc:
Expand Down
18 changes: 6 additions & 12 deletions lib/irb/extend-command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ module ExtendCommandBundle
# See #install_alias_method.
OVERRIDE_ALL = 0x02

# Quits the current irb context
#
# +ret+ is the optional signal or message to send to Context#exit
#
# Same as <code>IRB.CurrentContext.exit</code>.
def irb_exit(ret = 0)
irb_context.exit(ret)
end

# Displays current configuration.
#
# Modifying the configuration is achieved by sending a message to IRB.conf.
Expand All @@ -35,13 +26,16 @@ def irb_context
@ALIASES = [
[:context, :irb_context, NO_OVERRIDE],
[:conf, :irb_context, NO_OVERRIDE],
[:irb_quit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
[:exit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
[:quit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
]


@EXTEND_COMMANDS = [
[
:irb_exit, :Exit, "cmd/exit",
[:exit, OVERRIDE_PRIVATE_ONLY],
[:quit, OVERRIDE_PRIVATE_ONLY],
[:irb_quit, OVERRIDE_PRIVATE_ONLY],
],
[
:irb_current_working_workspace, :CurrentWorkingWorkspace, "cmd/chws",
[:cwws, NO_OVERRIDE],
Expand Down