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.

Differences Between: [Versions 310 and 400] [Versions 311 and 400]

Class cli_helper

Copyright: 2020 Marina Glancy
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 405 lines (14 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

cli_helper:: (15 methods):
  __construct()
  options_definitions()
  print_help()
  get_cli_option()
  cli_write()
  cli_problem()
  cli_writeln()
  cli_error()
  die()
  convert_to_table()
  print_help_options()
  process()
  mock_form()
  prepare_form_elements_for_cli()
  get_stats()


Class: cli_helper  - X-Ref

Helper method for CLI script to upload users (also has special wrappers for cli* functions for phpunit testing)

__construct(?string $progresstrackerclass = null)   X-Ref
cli_helper constructor.

param: string|null $progresstrackerclass

options_definitions()   X-Ref
Options used in this CLI script

return: array

print_help()   X-Ref
Print help for export


get_cli_option(string $key)   X-Ref
Get CLI option

return: mixed|null
param: string $key

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

param: string $text text to be written

cli_problem($text)   X-Ref
Write error notification

return: void
param: string $text

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

param: string $text text to be written

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

die($errorcode)   X-Ref
Wrapper for "die()" method so we can unittest it

param: mixed $errorcode

convert_to_table(array $column1, array $column2, int $indent = 0)   X-Ref
Display as CLI table

return: string
param: array $column1
param: array $column2
param: int $indent

print_help_options(array $options)   X-Ref
Display available CLI options as a table

param: array $options

process()   X-Ref
Process the upload


mock_form(array $customdata, array $submitteddata)   X-Ref
Mock form submission

return: \admin_uploaduser_form2
param: array $customdata
param: array $submitteddata

prepare_form_elements_for_cli(array $elements, array $defaults)   X-Ref
Prepare form elements for CLI

return: array
param: \HTML_QuickForm_element[] $elements
param: array $defaults

get_stats()   X-Ref
Get process statistics.

return: array