Skip to content
This repository was archived by the owner on Jul 30, 2026. It is now read-only.
Josh edited this page Apr 23, 2018 · 1 revision

This class contains a few helpers for scripts running in a CLI context.

Use:
blobfolio\common\cli

colorize()

Generate a BASH color-coded string (that you can later, e.g., echo). See here for formatting examples.

Arguments

This method accepts any number of arguments, each one representing a substring and style codes, if any, to apply to that substring.

There are three basic ways to construct an argument for this method:

Type Value Example
string Just a string, no formatting. "Hello World"
array An array containing a string followed by any number of codes. ["Hello World", 33, 1]
array An array containing a string followed by an array containing codes. ["Hello World", [33, 1]]

Returns

Returns a styled string. If more than one argument is passed, the result is concatenated.

Example

echo \blobfolio\common\cli::colorize(
    array(
        'Error: ',
        31,
        1
    ),
    'The script died.',
);

// \033[31;1mError: [0mThe script died.
// i.e. "Error:" would be red and bold, the rest normal.

is_cli()

Report whether or not a script is being run in CLI mode.

Returns

Returns TRUE if CLI mode, FALSE if not.

is_root()

Report whether or not the script is being run with sudo/root privileges. Note: this requires posix_getuid() support.

Returns

Returns TRUE if root, FALSE if not or if posix_getuid() is not available.

CLI

Constants

Dom Helpers

Files and Paths

Formatting

General Data Helpers

Images

Multi-Byte Wrappers

Sanitizing and Validation

Typecasting

Clone this wiki locally