r62955 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62954‎ | r62955 | r62956 >
Date:11:56, 25 February 2010
Author:happydog
Status:ok (Comments)
Tags:
Comment:
Update to the maybeHelp() function in Maintenance.php, to tidy the way help output is displayed on the command-line:

* Only display the file name as part of the command, rather than the full path to it (when the path is long it was virtually unreadable).
* Wrap the option/parameter descriptions so that they sit neatly on the screen. Previously if a description ran to multiple lines it wrapped to column 1, possibly in the middle of a word. Now it wraps neatly and the subsequent lines are indented to make it clearer to read.

For now I have hard-coded the screen width to 80 characters, which is a sub-optimal solution. However I do not know how to get the current screen-width in a system-agnostic way, so I will leave that detail for some-one else to flesh out.
Modified paths:
  • /branches/REL1_16/phase3/maintenance/Maintenance.php (modified) (history)

Diff [purge]

Index: branches/REL1_16/phase3/maintenance/Maintenance.php
@@ -565,6 +565,10 @@
566566 * @param $force boolean Whether to force the help to show, default false
567567 */
568568 protected function maybeHelp( $force = false ) {
 569+ $screenWidth = 80; // TODO: Caculate this!
 570+ $tab = " ";
 571+ $descWidth = $screenWidth - ( 2 * strlen( $tab ) );
 572+
569573 ksort( $this->mParams );
570574 if( $this->hasOption( 'help' ) || $force ) {
571575 $this->mQuiet = false;
@@ -572,7 +576,7 @@
573577 if( $this->mDescription ) {
574578 $this->output( "\n" . $this->mDescription . "\n" );
575579 }
576 - $output = "\nUsage: php " . $this->mSelf;
 580+ $output = "\nUsage: php " . basename( $this->mSelf );
577581 if( $this->mParams ) {
578582 $output .= " [--" . implode( array_keys( $this->mParams ), "|--" ) . "]";
579583 }
@@ -586,10 +590,12 @@
587591 }
588592 $this->output( "$output\n" );
589593 foreach( $this->mParams as $par => $info ) {
590 - $this->output( "\t$par : " . $info['desc'] . "\n" );
 594+ $this->output( wordwrap( "$tab$par : " . $info['desc'], $descWidth,
 595+ "\n$tab$tab" ) . "\n" );
591596 }
592597 foreach( $this->mArgList as $info ) {
593 - $this->output( "\t<" . $info['name'] . "> : " . $info['desc'] . "\n" );
 598+ $this->output( wordwrap( "$tab<" . $info['name'] . "> : " .
 599+ $info['desc'], $descWidth, "\n$tab$tab" ) . "\n" );
594600 }
595601 die( 1 );
596602 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r63734Porting my update to the maybeHelp() function in Maintenance.php into the tru...happydog11:38, 14 March 2010
r63735Fixing up r62955 - changing tabs to spaces, as suggested by NikeRabbit (http:...happydog11:45, 14 March 2010

Comments

#Comment by Nikerabbit (talk | contribs)   12:23, 25 February 2010

Was this supposed to go to trunk? The same weird four tab indentation again.

#Comment by HappyDog (talk | contribs)   19:32, 25 February 2010

> Was this supposed to go to trunk?

Yes, why?

(I will fix the indentation issue shortly.)

#Comment by HappyDog (talk | contribs)   11:47, 14 March 2010

Oops - I've just seen what you meant!  :-) It *was* supposed to be in trunk, and that's where I thought I'd put it. D'oh!

Have ported the changes into trunk in r63734. I also fixed the tabbing in that commit to use spaces instead.

I also back-ported the tab->space fix into the branch in r63735, for completeness.

Status & tagging log