lib/tty/exit.rb
# Provide exit code for a name or status
#
# @example
#   TTY::Exit.exit_code(:usage_error)
#   # => 64
#
# @param [String,Integer] name_or_code
#
# @return [Integer]
#   the exit code
#
# @api public
Provide exit code for a name or status
Provide exit code for a name or status
def exit_code(name_or_code = :ok)
      case name_or_code
      when String, Symbol
        (Registry.exits[name_or_code.to_sym] || {})[:code] ||
          NAME_TO_EXIT_CODE.fetch(name_or_code.to_sym) do
            raise Error, "Name '#{name_or_code}' isn't recognized."
          end
      when Numeric
        if exit_valid?(name_or_code.to_i)
          name_or_code.to_i
        else
          raise Error, "Provided code outside of the range (0 - 255)"
        end
      else
        raise Error, "Provide a name or a number as an exit code"
      end
    end
def exit_code ( name_or_code = :ok ) case name_or_code when String , Symbol ( Registry . exits [ name_or_code . to_sym ] || { } ) [ :code ] || NAME_TO_EXIT_CODE . fetch ( name_or_code . to_sym ) do raise Error , "Name '#{name_or_code}' isn't recognized." end when Numeric if exit_valid? ( name_or_code . to_i ) name_or_code . to_i else raise Error , "Provided code outside of the range (0 - 255)" end else raise Error , "Provide a name or a number as an exit code" end end
Provide exit code for a name or status
Provide exit code for a name or status
the exit code
the exit code
Integer
name_or_code
<not_specific>
<not_specific>
None
example
None
api
None