Index: trunk/phase3/maintenance/Maintenance.php |
— | — | @@ -96,6 +96,11 @@ |
97 | 97 | // a default with setBatchSize() |
98 | 98 | protected $mBatchSize = null; |
99 | 99 | |
| 100 | + // Generic options added by addDefaultParams() |
| 101 | + private $mGenericParameters = array(); |
| 102 | + // Generic options which might or not be supported by the script |
| 103 | + private $mDependantParameters = array(); |
| 104 | + |
100 | 105 | /** |
101 | 106 | * List of all the core maintenance scripts. This is added |
102 | 107 | * to scripts added by extensions in $wgMaintenanceScripts |
— | — | @@ -379,6 +384,9 @@ |
380 | 385 | * Add the default parameters to the scripts |
381 | 386 | */ |
382 | 387 | protected function addDefaultParams() { |
| 388 | + |
| 389 | + # Generic (non script dependant) options: |
| 390 | + |
383 | 391 | $this->addOption( 'help', 'Display this help message' ); |
384 | 392 | $this->addOption( 'quiet', 'Whether to supress non-error output' ); |
385 | 393 | $this->addOption( 'conf', 'Location of LocalSettings.php, if not default', false, true ); |
— | — | @@ -388,6 +396,12 @@ |
389 | 397 | $this->addOption( 'server', "The protocol and server name to use in URLs, e.g. " . |
390 | 398 | "http://en.wikipedia.org. This is sometimes necessary because " . |
391 | 399 | "server name detection may fail in command line scripts.", false, true ); |
| 400 | + |
| 401 | + # Save generic options to display them separately in help |
| 402 | + $this->mGenericParameters = $this->mParams ; |
| 403 | + |
| 404 | + # Script dependant options: |
| 405 | + |
392 | 406 | // If we support a DB, show the options |
393 | 407 | if ( $this->getDbType() > 0 ) { |
394 | 408 | $this->addOption( 'dbuser', 'The DB user to use for this script', false, true ); |
— | — | @@ -398,6 +412,9 @@ |
399 | 413 | $this->addOption( 'batch-size', 'Run this many operations ' . |
400 | 414 | 'per batch, default: ' . $this->mBatchSize, false, true ); |
401 | 415 | } |
| 416 | + # Save additional script dependant options to display |
| 417 | + # them separately in help |
| 418 | + $this->mDependantParameters = array_diff_key( $this->mParams, $this->mGenericParameters ); |
402 | 419 | } |
403 | 420 | |
404 | 421 | /** |
— | — | @@ -693,24 +710,68 @@ |
694 | 711 | } |
695 | 712 | $this->output( "$output\n\n" ); |
696 | 713 | |
697 | | - // Parameters description |
698 | | - foreach ( $this->mParams as $par => $info ) { |
| 714 | + # TODO abstract some repetitive code below |
| 715 | + |
| 716 | + // Generic parameters |
| 717 | + $this->output( "Generic maintenance parameters:\n" ); |
| 718 | + foreach ( $this->mGenericParameters as $par => $info ) { |
699 | 719 | $this->output( |
700 | 720 | wordwrap( "$tab--$par: " . $info['desc'], $descWidth, |
701 | 721 | "\n$tab$tab" ) . "\n" |
702 | 722 | ); |
703 | 723 | } |
| 724 | + $this->output( "\n" ); |
704 | 725 | |
705 | | - // Arguments description |
706 | | - foreach ( $this->mArgList as $info ) { |
707 | | - $openChar = $info['require'] ? '<' : '['; |
708 | | - $closeChar = $info['require'] ? '>' : ']'; |
709 | | - $this->output( |
710 | | - wordwrap( "$tab$openChar" . $info['name'] . "$closeChar: " . |
711 | | - $info['desc'], $descWidth, "\n$tab$tab" ) . "\n" |
712 | | - ); |
| 726 | + $scriptDependantParams = $this->mDependantParameters; |
| 727 | + if( count($scriptDependantParams) > 0 ) { |
| 728 | + $this->output( "Script dependant parameters:\n" ); |
| 729 | + // Parameters description |
| 730 | + foreach ( $scriptDependantParams as $par => $info ) { |
| 731 | + $this->output( |
| 732 | + wordwrap( "$tab--$par: " . $info['desc'], $descWidth, |
| 733 | + "\n$tab$tab" ) . "\n" |
| 734 | + ); |
| 735 | + } |
| 736 | + $this->output( "\n" ); |
713 | 737 | } |
714 | 738 | |
| 739 | + |
| 740 | + // Script specific parameters not defined on construction by |
| 741 | + // Maintenance::addDefaultParams() |
| 742 | + $scriptSpecificParams = array_diff_key( |
| 743 | + # all script parameters: |
| 744 | + $this->mParams, |
| 745 | + # remove the Maintenance default parameters: |
| 746 | + $this->mGenericParameters, |
| 747 | + $this->mDependantParameters |
| 748 | + ); |
| 749 | + if( count($scriptSpecificParams) > 0 ) { |
| 750 | + $this->output( "Script specific parameters:\n" ); |
| 751 | + // Parameters description |
| 752 | + foreach ( $scriptSpecificParams as $par => $info ) { |
| 753 | + $this->output( |
| 754 | + wordwrap( "$tab--$par: " . $info['desc'], $descWidth, |
| 755 | + "\n$tab$tab" ) . "\n" |
| 756 | + ); |
| 757 | + } |
| 758 | + $this->output( "\n" ); |
| 759 | + } |
| 760 | + |
| 761 | + // Print arguments |
| 762 | + if( count( $this->mArgList ) > 0 ) { |
| 763 | + $this->output( "Arguments:\n" ); |
| 764 | + // Arguments description |
| 765 | + foreach ( $this->mArgList as $info ) { |
| 766 | + $openChar = $info['require'] ? '<' : '['; |
| 767 | + $closeChar = $info['require'] ? '>' : ']'; |
| 768 | + $this->output( |
| 769 | + wordwrap( "$tab$openChar" . $info['name'] . "$closeChar: " . |
| 770 | + $info['desc'], $descWidth, "\n$tab$tab" ) . "\n" |
| 771 | + ); |
| 772 | + } |
| 773 | + $this->output( "\n" ); |
| 774 | + } |
| 775 | + |
715 | 776 | die( 1 ); |
716 | 777 | } |
717 | 778 | |