class

ToposPlayground::Command

Inherits Reference < Object

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.

Constructors

new(config : Config)
Source

Class methods

config
Source
config=(config : Config)
Source
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.

Source
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.

Source
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.

Source
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.

Source
run_process(command, chdir = ".", env : Process::Env = nil, shell : Bool = true)
Source

Instance methods

config
Source
config=(config : Config)
Source
run

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

Source
run_process(command, chdir = ".", env : Process::Env = nil, shell : Bool = true)
Source
run_process(command, chdir = ".", background : Bool = false, env : Process::Env = nil)
Source

Nested types