module Executable
Executable
is a mixin for creating robust, inheritable and reusable command line interfaces.
Constants
- Legacy
Variation of
Executable
which provides basic compatibility with previous versions ofExecutable
. It provides a call method that automatically dispatches to public methods.Among other uses,
Dispatch
can be useful for dropping into any class as a quick and dirty way to work with it on the command line.@since 1.2.0
Public Class Methods
When Exectuable
is included into a class, the class is also extended by ‘Executable::Doamin`.
# File lib/executable.rb, line 19 def self.included(base) base.extend Domain end
Default initializer, simply takes a hash of settings to set attributes via writer methods. Not existant attributes are simply ignored.
# File lib/executable.rb, line 28 def initialize(settings={}) settings.each do |k,v| __send__("#{k}=", v) if respond_to?("#{k}=") end end
Public Instance Methods
Command
invocation abstract method.
# File lib/executable.rb, line 39 def call(*args) #puts cli.show_help # TODO: show help instead of error ? raise NotImplementedError end
Access to underlying Help
instance.
# File lib/executable.rb, line 63 def cli self.class.cli end
Override option_missing
if needed. This receives the name of the option and the remaining arguments list. It must consume any arguments it uses from the begining of the list (i.e. in-place manipulation).
# File lib/executable.rb, line 72 def option_missing(opt, argv) raise NoOptionError, opt end
Convert Executable
to Proc object.
# File lib/executable.rb, line 47 def to_proc lambda { |*args| call(*args) } end
Output command line help.
# File lib/executable.rb, line 56 def to_s self.class.help.to_s # usage ? end