From 48843f424729be48d6f69c5ff0a512cc8e044638 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Mon, 25 Oct 2010 16:23:56 +0000 Subject: [PATCH] * bypassers ($force, --help) moved to the top. Less error prone. * prefix parameters with double dashes '--' * get ride of spaces before semi-column ':' * some comments to help us read the code tip: reviewers should strip white spaces (svn diff -x -ub) --- maintenance/Maintenance.php | 72 +++++++++++-------- maintenance/tests/phpunit/includes/IPTest.php | 10 +++ 2 files changed, 52 insertions(+), 30 deletions(-) diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index b660e8dd24..714f51fe22 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -633,44 +633,56 @@ abstract class Maintenance { * @param $force boolean Whether to force the help to show, default false */ protected function maybeHelp( $force = false ) { + if( !$force && !$this->hasOption( 'help' ) ) { + return; + } + $screenWidth = 80; // TODO: Caculate this! $tab = " "; $descWidth = $screenWidth - ( 2 * strlen( $tab ) ); ksort( $this->mParams ); - if ( $this->hasOption( 'help' ) || $force ) { - $this->mQuiet = false; + $this->mQuiet = false; - if ( $this->mDescription ) { - $this->output( "\n" . $this->mDescription . "\n" ); - } - $output = "\nUsage: php " . basename( $this->mSelf ); - if ( $this->mParams ) { - $output .= " [--" . implode( array_keys( $this->mParams ), "|--" ) . "]"; - } - if ( $this->mArgList ) { - $output .= " <"; - foreach ( $this->mArgList as $k => $arg ) { - $output .= $arg['name'] . ">"; - if ( $k < count( $this->mArgList ) - 1 ) - $output .= " <"; - } - } - $this->output( "$output\n" ); - foreach ( $this->mParams as $par => $info ) { - $this->output( - wordwrap( "$tab$par : " . $info['desc'], $descWidth, - "\n$tab$tab" ) . "\n" - ); - } - foreach ( $this->mArgList as $info ) { - $this->output( - wordwrap( "$tab<" . $info['name'] . "> : " . - $info['desc'], $descWidth, "\n$tab$tab" ) . "\n" - ); + // Description ... + if ( $this->mDescription ) { + $this->output( "\n" . $this->mDescription . "\n" ); + } + $output = "\nUsage: php " . basename( $this->mSelf ); + + // ... append parameters ... + if ( $this->mParams ) { + $output .= " [--" . implode( array_keys( $this->mParams ), "|--" ) . "]"; + } + + // ... and append arguments. + if ( $this->mArgList ) { + $output .= " <"; + foreach ( $this->mArgList as $k => $arg ) { + $output .= $arg['name'] . ">"; + if ( $k < count( $this->mArgList ) - 1 ) + $output .= " <"; } - die( 1 ); } + $this->output( "$output\n\n" ); + + // Parameters description + foreach ( $this->mParams as $par => $info ) { + $this->output( + wordwrap( "$tab--$par: " . $info['desc'], $descWidth, + "\n$tab$tab" ) . "\n" + ); + } + + // Arguments description + foreach ( $this->mArgList as $info ) { + $this->output( + wordwrap( "$tab<" . $info['name'] . ">: " . + $info['desc'], $descWidth, "\n$tab$tab" ) . "\n" + ); + } + + die( 1 ); } /** diff --git a/maintenance/tests/phpunit/includes/IPTest.php b/maintenance/tests/phpunit/includes/IPTest.php index 2336086f3c..181379c1f0 100644 --- a/maintenance/tests/phpunit/includes/IPTest.php +++ b/maintenance/tests/phpunit/includes/IPTest.php @@ -140,4 +140,14 @@ class IPTest extends PHPUnit_Framework_TestCase { $this->assertNet( '10.128.0.0' , '10.135.0.0/9' ); $this->assertNet( '134.0.0.0' , '134.0.5.1/8' ); } + + function testIPv6SpecialRanges() { + $this->assertTrue( IPv6::isULA( 'fdc1:9d57:401e::' ) ); + $this->assertTrue( IPv6::isULA( 'FDC1:9D57:401E::' ) ); + $this->assertTrue( IPv6::isULA( 'fc::' ) ); + $this->assertTrue( IPv6::isULA( 'fdff:ffff:ffff::' ) ); + + $this->assertFalse( IPv6::isULA( '2001:0DB8::A:1::' ) ); + $this->assertFalse( IPv6::isULA( '::1' ) ); + } } -- 2.20.1