\Drupal\strata\Drush\Commands StrataOutputTrait

Shared option reading, rendering and confirmation for the command suite.

Prose goes to standard error and structured results go to standard output. A command that printed its summary to standard output would put that summary inside the document --format=json produced, and the document would no longer parse.

Byte counts, moments and digests are rendered in one place, so the same commit reads the same way in a listing, a diff and a rollback plan.

Summary

Methods
Properties
Constants
No public methods found
No public properties found
No public constants found
value
number
flag
ref
prose
agreed
announce
bytes
moment
digest
duration
yesNo
No protected properties found
No protected constants found
No private methods found
No private properties found
No private constants found

Methods

value()

value(array  $options, string  $name) : string|null

Reads an option that carries a value.

A value option declares DrushCommands::REQ as its default, and Drush replaces that with the string the operator supplied or with NULL before the command body runs. A method called directly - from a test, a hook, or another command - still sees the sentinel, and both forms mean that nothing was supplied. Drush only ever passes a string, so an integer sentinel cannot be confused with a value.

Parameters

array $options

The options the command was called with.

string $name

The option name.

Returns

string|null —

The value, or NULL when none was supplied.

number()

number(array  $options, string  $name, int  $fallback) : int

Reads an option that carries a whole number.

Parameters

array $options

The options the command was called with.

string $name

The option name.

int $fallback

What to return when nothing was supplied.

Returns

int —

The value, or the fallback.

flag()

flag(array  $options, string  $name) : bool

Whether a flag was given.

Parameters

array $options

The options the command was called with.

string $name

The option name.

Returns

bool —

TRUE when the flag was supplied.

ref()

ref(array  $options) : string

The ref an option set names.

Parameters

array $options

The options the command was called with.

Returns

string —

The ref name, or the main ref when none was supplied.

prose()

prose() : \Symfony\Component\Console\Style\SymfonyStyle

The style prose is written to.

Returns

\Symfony\Component\Console\Style\SymfonyStyle —

A style over standard error.

agreed()

agreed(string  $question) : bool

Asks before doing something that removes a restore target or overwrites live data.

Drush answers this itself under --yes and --no, so a scripted run never blocks. The default is no, because the question is only ever asked about something irreversible.

Parameters

string $question

What is about to happen, phrased as a question.

Returns

bool —

TRUE to go ahead.

announce()

announce(bool  $acted, string  $summary) : void

States what a pass did, at the severity the outcome deserves.

A pass that ran and a pass that declined to run both produce a summary worth reading, and the difference between them is what an operator watching a scheduled job needs to see.

Parameters

bool $acted

TRUE when the pass did the thing it was asked to do.

string $summary

The one-line summary to print.

Returns

void —

bytes()

bytes(int  $bytes) : string

Renders a byte count at a readable scale.

Parameters

int $bytes

The count.

Returns

string —

For example "4.0 MiB".

moment()

moment(int  $microtime) : string

Renders unix microseconds as a timestamp.

Parameters

int $microtime

Microseconds since the epoch, or zero for no moment at all.

Returns

string —

An ISO-8601 timestamp, or "-".

digest()

digest(string|null  $digest) : string

Shortens a content address for a table cell.

Anything that is not a digest is returned whole, so an object key or a refusal reason passed here is readable rather than truncated to twelve characters of a path.

Parameters

string|null $digest

The digest, or NULL.

Returns

string —

The first twelve characters of a digest, the value unchanged when it is not one, or "-".

duration()

duration(float  $seconds) : string

Renders a duration.

Parameters

float $seconds

The duration.

Returns

string —

For example "1.24s".

yesNo()

yesNo(bool  $value) : string

Renders a boolean as a word.

Parameters

bool $value

The value.

Returns

string —

Either "yes" or "no".