Class: Inch::CLI::Command::Base Abstract

Inherits:
Object
  • Object
show all
Includes:
TraceHelper
Defined in:
lib/inch/cli/command/base.rb

Overview

This class is abstract.
Note:

This was adapted from YARD.

Abstract base class for CLI utilities. Provides some helper methods for the option parser

Direct Known Subclasses

BaseList, BaseObject

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TraceHelper

#debug, #trace, #trace_header

Constructor Details

#initializeBase

Returns a new instance of Base.



23
24
25
26
27
# File 'lib/inch/cli/command/base.rb', line 23

def initialize
  options_class = "Command::Options::#{self.class.to_s.split('::').last}"
  @options = eval(options_class).new
  @options.usage = usage
end

Instance Attribute Details

#source_parserObject (readonly)

Returns the value of attribute source_parser.



13
14
15
# File 'lib/inch/cli/command/base.rb', line 13

def source_parser
  @source_parser
end

Class Method Details

.run(*args) ⇒ Object

Helper method to run the utility on an instance.

See Also:

  • #run


17
18
19
20
21
# File 'lib/inch/cli/command/base.rb', line 17

def self.run(*args)
  command = new
  command.run(*args)
  command
end

Instance Method Details

#descriptionString

Returns a description of the command

Returns:

  • (String)


31
32
33
# File 'lib/inch/cli/command/base.rb', line 31

def description
  ""
end

#nameString

Returns the name of the command by which it is referenced in the command list.

Returns:

  • (String)


38
39
40
41
42
# File 'lib/inch/cli/command/base.rb', line 38

def name
  CommandParser.commands.each do |name, klass|
    return name if klass == self.class
  end
end

#usageString

Returns a description of the command’s usage pattern

Returns:

  • (String)


46
47
48
# File 'lib/inch/cli/command/base.rb', line 46

def usage
  "Usage: inch #{name} [options]"
end