Porting my update to the maybeHelp() function in Maintenance.php into the trunk....
authorMark Clements <happydog@users.mediawiki.org>
Sun, 14 Mar 2010 11:38:18 +0000 (11:38 +0000)
committerMark Clements <happydog@users.mediawiki.org>
Sun, 14 Mar 2010 11:38:18 +0000 (11:38 +0000)
--------------------------
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.
--------------------------

maintenance/Maintenance.php

index 45867b1..409d399 100644 (file)
@@ -565,6 +565,10 @@ abstract class Maintenance {
         * @param $force boolean Whether to force the help to show, default false
         */
        protected function maybeHelp( $force = false ) {
+               $screenWidth = 80;      // TODO: Caculate this!
+               $tab = "    ";
+               $descWidth = $screenWidth - ( 2 * strlen( $tab ) );
+               
                ksort( $this->mParams );
                if( $this->hasOption( 'help' ) || $force ) {
                        $this->mQuiet = false;
@@ -572,7 +576,7 @@ abstract class Maintenance {
                        if( $this->mDescription ) {
                                $this->output( "\n" . $this->mDescription . "\n" );
                        }
-                       $output = "\nUsage: php " . $this->mSelf;
+                       $output = "\nUsage: php " . basename( $this->mSelf );
                        if( $this->mParams ) {
                                $output .= " [--" . implode( array_keys( $this->mParams ), "|--" ) . "]";
                        }
@@ -586,10 +590,12 @@ abstract class Maintenance {
                        }
                        $this->output( "$output\n" );
                        foreach( $this->mParams as $par => $info ) {
-                               $this->output( "\t$par : " . $info['desc'] . "\n" );
+                               $this->output( wordwrap( "$tab$par : " . $info['desc'], $descWidth, 
+                                              "\n$tab$tab" ) . "\n" );
                        }
                        foreach( $this->mArgList as $info ) {
-                               $this->output( "\t<" . $info['name'] . "> : " . $info['desc'] . "\n" );
+                               $this->output( wordwrap( "$tab<" . $info['name'] . "> : " .
+                                              $info['desc'], $descWidth, "\n$tab$tab" ) . "\n" );
                        }
                        die( 1 );
                }