mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
modify lib/ and spec/ to use Pry::Slop
This commit is contained in:
parent
cab1e094fa
commit
52d88cdd6b
7 changed files with 17 additions and 17 deletions
|
@ -126,7 +126,7 @@ require 'shellwords'
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
require 'strscan'
|
require 'strscan'
|
||||||
require 'coderay'
|
require 'coderay'
|
||||||
require 'slop'
|
require 'pry/slop'
|
||||||
require 'rbconfig'
|
require 'rbconfig'
|
||||||
require 'tempfile'
|
require 'tempfile'
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Pry
|
||||||
# as CLI options.
|
# as CLI options.
|
||||||
attr_accessor :input_args
|
attr_accessor :input_args
|
||||||
|
|
||||||
# Add another set of CLI options (a Slop block)
|
# Add another set of CLI options (a Pry::Slop block)
|
||||||
def add_options(&block)
|
def add_options(&block)
|
||||||
if options
|
if options
|
||||||
old_options = options
|
old_options = options
|
||||||
|
@ -68,16 +68,16 @@ class Pry
|
||||||
self.input_args = args
|
self.input_args = args
|
||||||
|
|
||||||
begin
|
begin
|
||||||
opts = Slop.parse!(
|
opts = Pry::Slop.parse!(
|
||||||
args,
|
args,
|
||||||
:help => true,
|
:help => true,
|
||||||
:multiple_switches => false,
|
:multiple_switches => false,
|
||||||
:strict => true,
|
:strict => true,
|
||||||
&options
|
&options
|
||||||
)
|
)
|
||||||
rescue Slop::InvalidOptionError
|
rescue Pry::Slop::InvalidOptionError
|
||||||
# Display help message on unknown switches and exit.
|
# Display help message on unknown switches and exit.
|
||||||
puts Slop.new(&options)
|
puts Pry::Slop.new(&options)
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ end
|
||||||
|
|
||||||
|
|
||||||
# Bring in options defined by plugins
|
# Bring in options defined by plugins
|
||||||
Slop.new do
|
Pry::Slop.new do
|
||||||
on "no-plugins" do
|
on "no-plugins" do
|
||||||
Pry.config.should_load_plugins = false
|
Pry.config.should_load_plugins = false
|
||||||
end
|
end
|
||||||
|
|
|
@ -531,7 +531,7 @@ class Pry
|
||||||
# subclasses.
|
# subclasses.
|
||||||
#
|
#
|
||||||
# Create subclasses using {Pry::CommandSet#create_command}, and override the
|
# Create subclasses using {Pry::CommandSet#create_command}, and override the
|
||||||
# `options(opt)` method to set up an instance of Slop, and the `process`
|
# `options(opt)` method to set up an instance of Pry::Slop, and the `process`
|
||||||
# method to actually run the command. If necessary, you can also override
|
# method to actually run the command. If necessary, you can also override
|
||||||
# `setup` which will be called before `options`, for example to require any
|
# `setup` which will be called before `options`, for example to require any
|
||||||
# gems your command needs to run, or to set up state.
|
# gems your command needs to run, or to set up state.
|
||||||
|
@ -607,15 +607,15 @@ class Pry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return the help generated by Slop for this command.
|
# Return the help generated by Pry::Slop for this command.
|
||||||
def help
|
def help
|
||||||
slop.help
|
slop.help
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return an instance of Slop that can parse either subcommands or the
|
# Return an instance of Pry::Slop that can parse either subcommands or the
|
||||||
# options that this command accepts.
|
# options that this command accepts.
|
||||||
def slop
|
def slop
|
||||||
Slop.new do |opt|
|
Pry::Slop.new do |opt|
|
||||||
opt.banner(unindent(self.class.banner))
|
opt.banner(unindent(self.class.banner))
|
||||||
subcommands(opt)
|
subcommands(opt)
|
||||||
options(opt)
|
options(opt)
|
||||||
|
@ -644,7 +644,7 @@ class Pry
|
||||||
# end
|
# end
|
||||||
def setup; end
|
def setup; end
|
||||||
|
|
||||||
# A method to setup Slop commands so it can parse the subcommands your
|
# A method to setup Pry::Slop commands so it can parse the subcommands your
|
||||||
# command expects. If you need to set up default values, use `setup`
|
# command expects. If you need to set up default values, use `setup`
|
||||||
# instead.
|
# instead.
|
||||||
#
|
#
|
||||||
|
@ -679,7 +679,7 @@ class Pry
|
||||||
# end
|
# end
|
||||||
def subcommands(cmd); end
|
def subcommands(cmd); end
|
||||||
|
|
||||||
# A method to setup Slop so it can parse the options your command expects.
|
# A method to setup Pry::Slop so it can parse the options your command expects.
|
||||||
#
|
#
|
||||||
# @note Please don't do anything side-effecty in the main part of this
|
# @note Please don't do anything side-effecty in the main part of this
|
||||||
# method, as it may be called by Pry at any time for introspection reasons.
|
# method, as it may be called by Pry at any time for introspection reasons.
|
||||||
|
@ -696,7 +696,7 @@ class Pry
|
||||||
|
|
||||||
# The actual body of your command should go here.
|
# The actual body of your command should go here.
|
||||||
#
|
#
|
||||||
# The `opts` mehod can be called to get the options that Slop has passed,
|
# The `opts` mehod can be called to get the options that Pry::Slop has passed,
|
||||||
# and `args` gives the remaining, unparsed arguments.
|
# and `args` gives the remaining, unparsed arguments.
|
||||||
#
|
#
|
||||||
# The return value of this method is discarded unless the command was
|
# The return value of this method is discarded unless the command was
|
||||||
|
|
|
@ -3,7 +3,7 @@ class Pry
|
||||||
module OptionsHelpers
|
module OptionsHelpers
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
# Add method options to the Slop instance
|
# Add method options to the Pry::Slop instance
|
||||||
def method_options(opt)
|
def method_options(opt)
|
||||||
@method_target = target
|
@method_target = target
|
||||||
opt.on :M, "instance-methods", "Operate on instance methods."
|
opt.on :M, "instance-methods", "Operate on instance methods."
|
||||||
|
|
|
@ -435,7 +435,7 @@ class Pry
|
||||||
# @return [Boolean] `true` if `val` is a command, `false` otherwise
|
# @return [Boolean] `true` if `val` is a command, `false` otherwise
|
||||||
def process_command_safely(val)
|
def process_command_safely(val)
|
||||||
process_command(val)
|
process_command(val)
|
||||||
rescue CommandError, Slop::InvalidOptionError, MethodSource::SourceNotFoundError => e
|
rescue CommandError, Pry::Slop::InvalidOptionError, MethodSource::SourceNotFoundError => e
|
||||||
Pry.last_internal_error = e
|
Pry.last_internal_error = e
|
||||||
output.puts "Error: #{e.message}"
|
output.puts "Error: #{e.message}"
|
||||||
true
|
true
|
||||||
|
|
|
@ -3,7 +3,7 @@ require_relative '../../helper'
|
||||||
describe Pry::Command::Cat::FileFormatter do
|
describe Pry::Command::Cat::FileFormatter do
|
||||||
before do
|
before do
|
||||||
@p = Pry.new
|
@p = Pry.new
|
||||||
@opt = Slop.new
|
@opt = Pry::Slop.new
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#file_and_line" do
|
describe "#file_and_line" do
|
||||||
|
|
|
@ -26,7 +26,7 @@ if ENV["SET_TRACE_FUNC"]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "Ruby v#{RUBY_VERSION} (#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"}), Pry v#{Pry::VERSION}, method_source v#{MethodSource::VERSION}, CodeRay v#{CodeRay::VERSION}, Slop v#{Slop::VERSION}"
|
puts "Ruby v#{RUBY_VERSION} (#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"}), Pry v#{Pry::VERSION}, method_source v#{MethodSource::VERSION}, CodeRay v#{CodeRay::VERSION}, Pry::Pry::Slop v#{Pry::Pry::Slop::VERSION}"
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.expect_with :rspec do |c|
|
config.expect_with :rspec do |c|
|
||||||
|
|
Loading…
Reference in a new issue