CliOutput
Extends:
Command output writer.
This writer is used by the output of the cli handler (Cli).
In case the value is an exception then it's treated as CliOutput._errorOutput otherwise the value is treated as CliOutput._successOutput.
When an action is executed through a handler it can define options for readers and writers via Metadata support. For instance, you can use it to provide a custom result for a specific handler:
class MyAction extends Mebo.Action{
// ...
async _perform(data){
// ...
}
async _after(err, value){
// defining a custom result that only affects the web handler
// this call could be done inside of the _perform method. However, we
// are defining it inside of the _after to keep _perform as
// abstract as possible. Since, _after is always called (even during
// an error) after the execution of the action, it provides a way to
// hook and define custom metadata related with the result.
if (!err){
// defining a custom output option
this.setMeta('$cliResult', {
message: 'My custom cli result!',
});
}
}
// ...
}
Options Summary
Option Name | Description | Default Value |
---|---|---|
result | Overrides the value returned by Writer.value to an arbitrary value (only affects the success output) | ![]() |
Constructor Summary
Public Constructor | ||
public |
constructor(value: *, stdout: stream, stderr: stream) Creates the cli output writer |
Method Summary
Public Methods | ||
public |
stderr(): stream Returns the stream used as stderr |
|
public |
stdout(): stream Returns the stream used as stdout |
Protected Methods | ||
protected |
Implements the response for an error value. |
|
protected |
Implements the response for a success value. |
Inherited Summary
From class Writer | ||
public |
Returns an option |
|
public |
Serializes a writer value (Writer.value) in case the value is an exception it's serialize as Writer._errorOutput otherwise it's serialized as Writer._successOutput. |
|
public |
Sets a value under the options |
|
public |
value(): * Returns the value that should be serialized (Writer.serialize) by the writer. |
|
protected |
Translates an Error to a data structure that is later serialized by a writer implementation as output. |
|
protected |
_successOutput(): Object | Stream Translates the success value to a data structure that is later serialized by a handler implementation as output. |
Public Constructors
public constructor(value: *, stdout: stream, stderr: stream) source
Creates the cli output writer
Override:
Writer#constructorParams:
Name | Type | Attribute | Description |
value | * | arbitrary value passed to the writer |
|
stdout | stream | stream used as stdout |
|
stderr | stream | stream used as stderr |
Public Methods
Protected Methods
protected _errorOutput() source
Implements the response for an error value.
The error output writes the error message under the stderr.
Override:
Writer#_errorOutputprotected _successOutput() source
Implements the response for a success value.
Readable streams are piped to Cli.stdout, otherwise the value is serialized using json.