Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

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

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

param: string $key
return: mixed|null

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

param: string $text
return: void

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

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

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

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

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

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

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

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

get_stats()   X-Ref
Get process statistics.

return: array