abstract class ToposPlayground::Command
- ToposPlayground::Command
- Reference
- Object
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
- ToposPlayground::Command::Clean
- ToposPlayground::Command::Logs
- ToposPlayground::Command::Start
- ToposPlayground::Command::Version
Defined in:
topos-playground/command.crConstructors
Class Method Summary
- .config : Config
- .config=(config : Config)
-
.levenshtein_options
If no command matches, the playground will attempt to find a command that might have been the intended command.
-
.log_to_file?(config)
For some commands, writing a physical log of execution isn't necessary.
-
.options(parser, config)
This class method is called when the playground is setting up its command line parser.
-
.run_process(command, chdir = ".", background : Bool = false, env : Process::Env = nil)
Convenience method for running a process and capturing its output.
- .run_process(command, chdir = ".", env : Process::Env = nil, shell : Bool = true)
Instance Method Summary
- #config : Config
- #config=(config : Config)
-
#run
All subclasses must implement
#run
, which is responsible for carrying out the logic of the command. - #run_process(command, chdir = ".", env : Process::Env = nil, shell : Bool = true)
- #run_process(command, chdir = ".", background : Bool = false, env : Process::Env = nil)
Constructor Detail
Class Method Detail
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.
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
.
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.
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.
Instance Method Detail
All subclasses must implement #run
, which is responsible for carrying out the
logic of the command.