abstract class ToposPlayground::Command

Overview

All commands inherit from this class. It provides the expected logging constant interfaces, handles registration with the command registry, and access to the topos-playground configuration. It also provides a couple convenience #run_process methods for running processes and capturing their output either synchronously or asynchronously.

Direct Known Subclasses

Defined in:

topos-playground/command.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(config : Config) #

[View source]

Class Method Detail

def self.config : Config #

[View source]
def self.config=(config : Config) #

[View source]
def self.levenshtein_options #

If no command matches, the playground will attempt to find a command that might have been the intended command. Each Command subclass can subclass this class method in order to return a list of possible commands to use in the levenshtein matching process.


[View source]
def self.log_to_file?(config) #

For some commands, writing a physical log of execution isn't necessary. This class method will be called on the command before the playground sets up the physical log, and if it returns false, the physical log will not be created. Subclasses that should log to a physical file should override this method to return true.


[View source]
def self.options(parser, config) #

This class method is called when the playground is setting up its command line parser. Any subclass can implement this method to add its own command line flags.


[View source]
def self.run_process(command, chdir = ".", background : Bool = false, env : Process::Env = nil) #

Convenience method for running a process and capturing its output. This method runs the process asynchronously, spawning two threads. One monitors an instance of Channel(Bool) and kills the process when it receives a message. This allows the process to be gracefully terminated when the user presses Ctrl-C.

The other thread monitors the output of the process, and passes it through the monitor_channel if verbose logging has been requested via the command line flags.

The method returns a tuple containing the kill_channel, monitor_channel, and process objects.


[View source]
def self.run_process(command, chdir = ".", env : Process::Env = nil, shell : Bool = true) #

[View source]

Instance Method Detail

def config : Config #

[View source]
def config=(config : Config) #

[View source]
abstract def run #

All subclasses must implement #run, which is responsible for carrying out the logic of the command.


[View source]
def run_process(command, chdir = ".", env : Process::Env = nil, shell : Bool = true) #

[View source]
def run_process(command, chdir = ".", background : Bool = false, env : Process::Env = nil) #

[View source]