Class: Inch::CLI::Command::Base Abstract
- Inherits:
-
Object
- Object
- Inch::CLI::Command::Base
- Includes:
- TraceHelper
- Defined in:
- lib/inch/cli/command/base.rb
Overview
Subclass and override #run to implement a new command
This was adapted from YARD github.com/lsegal/yard/blob/master/lib/yard/cli/command.rb
Abstract base class for CLI controller objects
Direct Known Subclasses
Instance Attribute Summary collapse
- #source_parser ⇒ SourceParser readonly
Class Method Summary collapse
-
.run(*args) ⇒ Command::Base
Helper method to run an instance with the given
args
.
Instance Method Summary collapse
-
#description ⇒ String
Returns a description of the command.
-
#initialize ⇒ Base
constructor
A new instance of Base.
-
#name ⇒ String
Returns the name of the command by which it is referenced in the command list.
-
#run(*args) ⇒ Object
abstract
Runs the command with the given
args
. -
#usage ⇒ String
Returns a description of the command’s usage pattern.
Methods included from TraceHelper
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
53 54 55 56 57 |
# File 'lib/inch/cli/command/base.rb', line 53 def initialize = "Command::Options::#{self.class.to_s.split('::').last}" @options = eval().new @options.usage = usage end |
Instance Attribute Details
#source_parser ⇒ SourceParser (readonly)
41 42 43 |
# File 'lib/inch/cli/command/base.rb', line 41 def source_parser @source_parser end |
Class Method Details
.run(*args) ⇒ Command::Base
Helper method to run an instance with the given args
47 48 49 50 51 |
# File 'lib/inch/cli/command/base.rb', line 47 def self.run(*args) command = new command.run(*args) command end |
Instance Method Details
#description ⇒ String
Returns a description of the command
62 63 64 |
# File 'lib/inch/cli/command/base.rb', line 62 def description "" end |
#name ⇒ String
Returns the name of the command by which it is referenced in the command list
70 71 72 73 74 |
# File 'lib/inch/cli/command/base.rb', line 70 def name CommandParser.commands.each do |name, klass| return name if klass == self.class end end |
#run(*args) ⇒ Object
Override with implementation
Runs the command with the given args
81 82 83 |
# File 'lib/inch/cli/command/base.rb', line 81 def run(*args) raise NotImplementedError end |
#usage ⇒ String
Returns a description of the command’s usage pattern
88 89 90 |
# File 'lib/inch/cli/command/base.rb', line 88 def usage "Usage: inch #{name} [options]" end |