summaryrefslogtreecommitdiff
path: root/lib/pry/commands/exit_all.rb
blob: e30373b4623bb9c830c16dbaa761f67b309b2be1 (plain)
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
# frozen_string_literal: true

class Pry
  class Command
    class ExitAll < Pry::ClassCommand
      match 'exit-all'
      group 'Navigating Pry'
      description 'End the current Pry session.'

      banner <<-'BANNER'
        Usage:   exit-all [--help]
        Aliases: !!@

        End the current Pry session (popping all bindings and returning to caller).
        Accepts optional return value.
      BANNER

      def process
        # calculate user-given value
        exit_value = target.eval(arg_string)

        # clear the binding stack
        pry_instance.binding_stack.clear

        # break out of the repl loop
        throw(:breakout, exit_value)
      end
    end

    Pry::Commands.add_command(Pry::Command::ExitAll)
    Pry::Commands.alias_command '!!@', 'exit-all'
  end
end