class Pry::ClassCommand
gems your command needs to run, or to set up state.
‘setup` which will be called before `options`, for example to require any
method to actually run the command. If necessary, you can also override
`options(opt)` method to set up an instance of Slop, and the `process`
Create subclasses using {Pry::CommandSet#create_command}, and override the
subclasses.
have, namely a –help switch, and then delegates actual processing to its
This class implements the bare-minimum functionality that a command should
A super-class of Commands with structure.
def call(*args)
-
(Object)- The return value of `process` or VOID_VALUE
Parameters:
-
args(Array) -- The arguments passed
def call(*args) setup self.opts = slop self.args = self.opts.parse!(args) if opts.present?(:help) output.puts slop.help void else process(*correct_arg_arity(method(:process).arity, args)) end end
def complete(search)
-
(Array- the words to complete)
Parameters:
-
search(String) -- The line typed so far
def complete(search) slop.map do |opt| [opt.long && "--#{opt.long} " || opt.short && "-#{opt.short}"] end.flatten(1).compact + super end
def doc
def doc new.help end
def help
def help slop.help end
def inherited(klass)
Ensure that subclasses inherit the options, description and
def inherited(klass) klass.match match klass.description description klass.command_options options end
def options(opt); end
- Note: - Please don't do anything side-effecty in the main part of this
def options(opt); end
def process; raise CommandError, "command '#{command_name}' not implemented" end
end
gist_method
else
gist_class
if opts.present?(:class)
def process
@example
repl.
created with `:keep_retval => true`, in which case it is returned to the
The return value of this method is discarded unless the command was
and `args` gives the remaining, unparsed arguments.
The `opts` mehod can be called to get the options that Slop has passed,
The actual body of your command should go here.
def process; raise CommandError, "command '#{command_name}' not implemented" end
def setup; end
@action = :method
require 'gist'
def setup
@example
for example requiring gems, or setting default values for options.
This method can be used to set up any context your command needs to run,
A method called just before `options(opt)` as part of `call`.
def setup; end
def slop
Return an instance of Slop::Commands that can parse either subcommands
def slop Slop.parse do |opt| opt.banner(unindent(self.class.banner)) subcommands(opt) options(opt) opt.on :h, :help, 'Show this message.' end end
def source
def source Pry::WrappedModule(self).source end
def source_file
def source_file Pry::WrappedModule(self).source_file end
def source_line
def source_line Pry::WrappedModule(self).source_line end
def source_location
def source_location Pry::WrappedModule(self).source_location end
def subcommands(cmd); end
- Example: Define the invokation block anywhere you want -
Example: A minimal example -
def subcommands(cmd); end