Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
/lib/ -> clilib.php (source)

Differences Between: [Versions 39 and 401]

Command line utility functions and classes

Copyright: 2009 Petr Skoda (http://skodak.org)
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 320 lines (10 kb)
Included or required: 7 times
Referenced: 0 times
Includes or requires: 0 files

Defines 11 functions


Functions that are not part of a class:

cli_write($text, $stream=STDOUT)   X-Ref
Write a text to the given stream

param: string $text text to be written
param: resource $stream output stream to be written to, defaults to STDOUT

cli_writeln($text, $stream=STDOUT)   X-Ref
Write a text followed by an end of line symbol to the given stream

param: string $text text to be written
param: resource $stream output stream to be written to, defaults to STDOUT

cli_input($prompt, $default='', array $options=null, $casesensitiveoptions=false)   X-Ref
Get input from user

param: string $prompt text prompt, should include possible options
param: string $default default value when enter pressed
param: array $options list of allowed options, empty means any text
param: bool $casesensitive true if options are case sensitive
return: string entered text

cli_get_params(array $longoptions, array $shortmapping=null)   X-Ref
Returns cli script parameters.

param: array $longoptions array of --style options ex:('verbose'=>false)
param: array $shortmapping array describing mapping of short to long style options ex:('h'=>'help', 'v'=>'verbose')
return: array array of arrays, options, unrecognised as optionlongname=>value

cli_set_process_title_suffix(string $suffix)   X-Ref
This sets the cli process title suffix

An example is appending current Task API info so a sysadmin can immediately
see what task a cron process is running at any given moment.

param: string $suffix process suffix

cli_separator($return=false)   X-Ref
Print or return section separator string

param: bool $return false means print, true return as string
return: mixed void or string

cli_heading($string, $return=false)   X-Ref
Print or return section heading string

param: string $string text
param: bool $return false means print, true return as string
return: mixed void or string

cli_problem($text)   X-Ref
Write error notification

param: $text
return: void

cli_error($text, $errorcode=1)   X-Ref
Write to standard error output and exit with the given code

param: string $text
param: int $errorcode
return: void (does not return)

cli_logo($padding=2, $return=false)   X-Ref
Print an ASCII version of the Moodle logo.

param: int $padding left padding of the logo
param: bool $return should we print directly (false) or return the string (true)
return: mixed void or string

cli_ansi_format(string $message)   X-Ref
Substitute cursor, colour, and bell placeholders in a CLI output to ANSI escape characters when ANSI is available.

param: string $message
return: string