Module: Executable

Included in:
Command
Defined in:
lib/executable.rb,
lib/executable/help.rb,
lib/executable/utils.rb,
lib/executable/domain.rb,
lib/executable/errors.rb,
lib/executable/parser.rb,
lib/executable/version.rb,
lib/executable/dispatch.rb,
lib/executable/completion.rb

Overview

Executable is a mixin for creating robust, inheritable and reusable command line interfaces.

Defined Under Namespace

Modules: Dispatch, Domain, Utils Classes: Command, Completion, Help, NoCommandError, NoOptionError, Parser

Constant Summary collapse

VERSION =
'1.3.0'
Legacy =

Dispatch is Legacy.

Dispatch

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

When Exectuable is included into a class, the class is also extended by Executable::Doamin.



20
21
22
# File 'lib/executable.rb', line 20

def self.included(base)
  base.extend Domain
end

Instance Method Details

#call(*args) ⇒ Object

Command invocation abstract method.

Raises:

  • (NotImplementedError)


40
41
42
43
# File 'lib/executable.rb', line 40

def call(*args)
  #puts cli.show_help           # TODO: show help instead of error ?
  raise NotImplementedError
end

#cliObject

Access to underlying cli instance.



64
65
66
# File 'lib/executable.rb', line 64

def cli
  self.class.cli
end

#initialize(settings = {}) ⇒ Object

Default initializer, simply takes a hash of settings to set attributes via writer methods. Not existant attributes are simply ignored.



29
30
31
32
33
# File 'lib/executable.rb', line 29

def initialize(settings={})
  settings.each do |k,v|
    __send__("#{k}=", v) if respond_to?("#{k}=")
  end
end

#inspectObject



52
# File 'lib/executable.rb', line 52

alias_method :inspect, :to_s

#option_missing(opt, argv) ⇒ Object

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).

Raises:



73
74
75
# File 'lib/executable.rb', line 73

def option_missing(opt, argv)
  raise NoOptionError, opt
end

#to_procObject

Convert Executable to Proc object.



48
49
50
# File 'lib/executable.rb', line 48

def to_proc
  lambda { |*args| call(*args) }
end

#to_sObject

Output command line help.



57
58
59
# File 'lib/executable.rb', line 57

def to_s
  self.class.help.to_s  # usage ?
end