MediaWiki  master
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 ) ) {
33  $optionsWithoutArgs = [];
34 }
35 if ( !isset( $allowUnregisteredOptions ) ) {
36  $allowUnregisteredOptions = false;
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 
71  $args = $this->mArgs;
72  $options = $this->mOptions;
73  }
74 }
75 
76 $maintClass = CommandLineInc::class;
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:86
global $optionsWithArgs
Definition: commandLine.inc:24
maybeHelp( $force=false)
No help, it would just be misleading since it misses custom options.
Definition: commandLine.inc:60
if( $line===false) $args
Definition: mcc.php:124
global $allowUnregisteredOptions
Definition: commandLine.inc:24
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
global $optionsWithoutArgs
Definition: commandLine.inc:24
$maintClass
Definition: commandLine.inc:76
setAllowUnregisteredOptions( $allow)
Sets whether to allow unregistered options, which are options passed to a script that do not match an...