Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
/lib/ -> clilib.php (source)

Differences Between: [Versions 39 and 400]

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

return: string entered text
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

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

return: array array of arrays, options, unrecognised as optionlongname=>value
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')

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

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

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

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

cli_problem($text)   X-Ref
Write error notification

return: void
param: $text

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

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

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

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

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.

return: string
param: string $message