Class: Matt::Command

Inherits:
Object
  • Object
show all
Includes:
Support::Puts
Defined in:
lib/matt/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support::Puts

#debug, #info, #puts_err, #puts_out, #stderr, #stdout

Constructor Details

#initialize {|_self| ... } ⇒ Command

Returns a new instance of Command.

Yields:

  • (_self)

Yield Parameters:

  • _self (Matt::Command)

    the object that the method was called on



40
41
42
43
44
# File 'lib/matt/command.rb', line 40

def initialize
  @output_format = :csv
  @to = nil
  yield(self) if block_given?
end

Instance Attribute Details

#exitcodeObject

Returns the value of attribute exitcode.



36
37
38
# File 'lib/matt/command.rb', line 36

def exitcode
  @exitcode
end

#output_formatObject

Returns the value of attribute output_format.



37
38
39
# File 'lib/matt/command.rb', line 37

def output_format
  @output_format
end

#toObject

Returns the value of attribute to.



38
39
40
# File 'lib/matt/command.rb', line 38

def to
  @to
end

Instance Method Details

#call(argv) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/matt/command.rb', line 69

def call(argv)
  ok = false
  catch :abort do
    parse_argv(argv)
    _call(argv)
    ok = true
  end
  self.exitcode = ok ? 0 : 1
end

#configurationObject



51
52
53
54
# File 'lib/matt/command.rb', line 51

def configuration
  return @configuration if @configuration
  self.configuration = Configuration.new(Path.pwd)
end

#configuration=(c) ⇒ Object



56
57
58
59
# File 'lib/matt/command.rb', line 56

def configuration=(c)
  @on_configuration.call(c) if @on_configuration
  @configuration = c
end

#has_configuration?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/matt/command.rb', line 61

def has_configuration?
  !!@configuration
end

#on_configuration(&bl) ⇒ Object



46
47
48
49
# File 'lib/matt/command.rb', line 46

def on_configuration(&bl)
  @on_configuration = bl
  self
end

#parse_argv(argv) ⇒ Object



65
66
67
# File 'lib/matt/command.rb', line 65

def parse_argv(argv)
  opt_parser.parse!(argv)
end