Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
/lib/ -> clilib.php (source)

Differences Between: [Versions 39 and 310] [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

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: 298 lines (9 kb)
Included or required: 7 times
Referenced: 0 times
Includes or requires: 0 files

Defines 10 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_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