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.

Subclass and override #run to implement a new command

Abstract base class for CLI controller objects

Direct Known Subclasses

BaseList, Diff

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TraceHelper

#ui

Constructor Details

#initialize(kwargs = {}) ⇒ Base



63
64
65
66
# File 'lib/inch/cli/command/base.rb', line 63

def initialize(kwargs = {})
  @ui = kwargs[:ui] if kwargs[:ui]
  initialize_cli_options
end

Instance Attribute Details

#codebaseCodebase::Proxy (readonly)



41
42
43
# File 'lib/inch/cli/command/base.rb', line 41

def codebase
  @codebase
end

Class Method Details

.register_command_as(name, default = false) ⇒ void

This method returns an undefined value.

Registers the current Command in the CommandParser



58
59
60
61
# File 'lib/inch/cli/command/base.rb', line 58

def self.register_command_as(name, default = false)
  CLI::CommandParser.default_command = name if default
  CLI::CommandParser.commands[name] = self
end

.run(*args) ⇒ Command::Base

Helper method to run an instance with the given args

See Also:



47
48
49
50
51
52
# File 'lib/inch/cli/command/base.rb', line 47

def self.run(*args)
  kwargs = args.last.is_a?(Hash) ? args.pop : {}
  command = new(kwargs)
  command.run(*args)
  command
end

Instance Method Details

#descriptionString

Returns a description of the command



71
72
73
# File 'lib/inch/cli/command/base.rb', line 71

def description
  ''
end

#nameString

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



79
80
81
82
83
# File 'lib/inch/cli/command/base.rb', line 79

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

#run(*_args) ⇒ Object

This method is abstract.
Note:

Override with implementation

Runs the command with the given args



90
91
92
# File 'lib/inch/cli/command/base.rb', line 90

def run(*_args)
  fail NotImplementedError
end

#usageString

Returns a description of the command's usage pattern



97
98
99
# File 'lib/inch/cli/command/base.rb', line 97

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