Class: Chemicalml::Cli::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/chemicalml/cli/command.rb

Overview

Base class for every command. Subclasses implement #run(options).

Each command receives a Chemicalml::Logger in its constructor. When dispatched via Thor (the normal CLI path), the logger is bridged to Thor's shell for coloured output. When invoked directly (MyCommand.new.run(options)), the logger writes plain text to $stderr.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger: Chemicalml::Logger.default) ⇒ Command

Returns a new instance of Command.

Parameters:

  • logger (Chemicalml::Logger) (defaults to: Chemicalml::Logger.default)

    the logger to use. Defaults to a plain stderr logger. The Thor dispatcher passes one bridged to Thor's shell for colour.



18
19
20
# File 'lib/chemicalml/cli/command.rb', line 18

def initialize(logger: Chemicalml::Logger.default)
  @logger = logger
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

Class Method Details

.run(options = {}, logger: Chemicalml::Logger.default) ⇒ Object



23
24
25
# File 'lib/chemicalml/cli/command.rb', line 23

def run(options = {}, logger: Chemicalml::Logger.default)
  new(logger: logger).run(options)
end

Instance Method Details

#run(_options = {}) ⇒ Object

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/chemicalml/cli/command.rb', line 28

def run(_options = {})
  raise NotImplementedError, "#{self.class} must implement #run"
end