MediaWiki  1.34.0
commandLine.inc
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Maintenance.php';
25 
26 // phpcs:ignore MediaWiki.NamingConventions.ValidGlobalName.wgPrefix
28 
29 if ( !isset( $optionsWithArgs ) ) {
30  $optionsWithArgs = [];
31 }
32 if ( !isset( $optionsWithoutArgs ) ) {
34 }
35 if ( !isset( $allowUnregisteredOptions ) ) {
37 }
38 
39 class CommandLineInc extends Maintenance {
40  public function __construct() {
41  // phpcs:ignore MediaWiki.NamingConventions.ValidGlobalName.wgPrefix
43 
44  parent::__construct();
45 
46  foreach ( $optionsWithArgs as $name ) {
47  $this->addOption( $name, '', false, true );
48  }
49  foreach ( $optionsWithoutArgs as $name ) {
50  $this->addOption( $name, '', false, false );
51  }
52 
53  $this->setAllowUnregisteredOptions( $allowUnregisteredOptions );
54  }
55 
60  protected function maybeHelp( $force = false ) {
61  if ( !$force ) {
62  return;
63  }
64  parent::maybeHelp( true );
65  }
66 
67  public function execute() {
68  // phpcs:ignore MediaWiki.NamingConventions.ValidGlobalName.wgPrefix
69  global $args, $options;
70 
72  $options = $this->mOptions;
73  }
74 }
75 
76 $maintClass = CommandLineInc::class;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
$optionsWithoutArgs
global $optionsWithoutArgs
Definition: commandLine.inc:24
$optionsWithArgs
global $optionsWithArgs
Definition: commandLine.inc:24
$maintClass
$maintClass
Definition: commandLine.inc:76
CommandLineInc
Definition: commandLine.inc:39
CommandLineInc\maybeHelp
maybeHelp( $force=false)
No help, it would just be misleading since it misses custom options.
Definition: commandLine.inc:60
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
$allowUnregisteredOptions
global $allowUnregisteredOptions
Definition: commandLine.inc:24
CommandLineInc\__construct
__construct()
Default constructor.
Definition: commandLine.inc:40
Maintenance\$mArgs
$mArgs
Definition: Maintenance.php:111
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:267
Maintenance\setAllowUnregisteredOptions
setAllowUnregisteredOptions( $allow)
Sets whether to allow unregistered options, which are options passed to a script that do not match an...
Definition: Maintenance.php:340
CommandLineInc\execute
execute()
Do the actual work.
Definition: commandLine.inc:67
$args
if( $line===false) $args
Definition: cdb.php:64
Maintenance\$mOptions
$mOptions
Definition: Maintenance.php:108