diff --git a/composer.json b/composer.json index 3ab00c2e19..1089be8f28 100644 --- a/composer.json +++ b/composer.json @@ -21,14 +21,19 @@ { "type": "vcs", "url": "https://github.com/wp-cli/composer-changelogs" + }, + { + "type": "git", + "url": "https://github.com/gitlost/php-cli-tools.git" } + ], "minimum-stability": "dev", "prefer-stable": true, "require": { "php": ">=5.3.29", "wp-cli/autoload-splitter": "^0.1", - "wp-cli/php-cli-tools": "~0.11.2", + "wp-cli/php-cli-tools": "dev-issue_4127", "mustache/mustache": "~2.4", "wp-cli/mustangostang-spyc": "^0.6.3", "composer/semver": "~1.0", diff --git a/composer.lock b/composer.lock index 28af6518ef..cc6701a292 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "4e43b8a956e6aff6833eb95246240c00", + "content-hash": "f86dc821d9f91c903ca16df45eb62448", "packages": [ { "name": "composer/ca-bundle", @@ -2219,17 +2219,11 @@ }, { "name": "wp-cli/php-cli-tools", - "version": "v0.11.2", + "version": "dev-issue_4127", "source": { "type": "git", - "url": "https://github.com/wp-cli/php-cli-tools.git", - "reference": "6d231e5538b2c0db909b2cb49d30a45faf20069a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/wp-cli/php-cli-tools/zipball/6d231e5538b2c0db909b2cb49d30a45faf20069a", - "reference": "6d231e5538b2c0db909b2cb49d30a45faf20069a", - "shasum": "" + "url": "https://github.com/gitlost/php-cli-tools.git", + "reference": "934580159334fd510056599a2925d720d93df6ea" }, "require": { "php": ">= 5.3.0" @@ -2243,20 +2237,19 @@ "lib/cli/cli.php" ] }, - "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ - { - "name": "James Logsdon", - "email": "jlogsdon@php.net", - "role": "Developer" - }, { "name": "Daniel Bachhuber", "email": "daniel@handbuilt.co", "role": "Maintainer" + }, + { + "name": "James Logsdon", + "email": "jlogsdon@php.net", + "role": "Developer" } ], "description": "Console utilities for PHP", @@ -2265,7 +2258,7 @@ "cli", "console" ], - "time": "2017-02-15T12:17:55+00:00" + "time": "2017-06-05 02:35:06" }, { "name": "wp-cli/rewrite-command", @@ -3274,7 +3267,7 @@ "support": { "source": "https://github.com/wp-cli/composer-changelogs/tree/php53" }, - "time": "2017-03-29T14:27:14+00:00" + "time": "2017-03-29 14:27:14" }, { "name": "roave/security-advisories", @@ -3422,6 +3415,7 @@ ], "minimum-stability": "dev", "stability-flags": { + "wp-cli/php-cli-tools": 20, "pyrech/composer-changelogs": 20, "roave/security-advisories": 20 }, diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index ed863a6271..96e1647dfa 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -73,6 +73,9 @@ private static function get_process_env_variables() { if ( $config_path = getenv( 'WP_CLI_CONFIG_PATH' ) ) { $env['WP_CLI_CONFIG_PATH'] = $config_path; } + if ( $term = getenv( 'TERM' ) ) { + $env['TERM'] = $term; + } return $env; } diff --git a/features/help.feature b/features/help.feature index b5c62b3e5e..176aa2c0db 100644 --- a/features/help.feature +++ b/features/help.feature @@ -5,27 +5,38 @@ Feature: Get help about WP-CLI commands When I run `wp help` Then STDOUT should not be empty + And STDOUT should contain: + """ + Run 'wp help ' to get more information on a specific command. + + """ + And STDERR should be empty When I run `wp help core` Then STDOUT should not be empty + And STDERR should be empty When I run `wp help core download` Then STDOUT should not be empty + And STDERR should be empty When I run `wp help help` Then STDOUT should not be empty + And STDERR should be empty When I run `wp help help` Then STDOUT should contain: """ GLOBAL PARAMETERS """ + And STDERR should be empty When I run `wp post list --post_type=post --posts_per_page=5 --help` Then STDOUT should contain: """ wp post list """ + And STDERR should be empty Scenario: Help when WordPress is downloaded but not installed Given an empty directory @@ -84,12 +95,14 @@ Feature: Get help about WP-CLI commands """ A dummy command. """ + And STDERR should be empty When I run `wp help test-help` Then STDOUT should contain: """ wp test-help """ + And STDERR should be empty Scenario: Help for incomplete commands Given an empty directory @@ -234,13 +247,25 @@ Feature: Get help about WP-CLI commands class Test_Wordwrap extends WP_CLI_Command { /** - * A dummy command. + * 123456789 123456789 123456789 123456789 123456789 123456789 123456789 12345678 * * ## OPTIONS * * [--skip-delete] * : Skip deletion of the original thumbnails. If your thumbnails are linked from sources outside your control, it's likely best to leave them around. Defaults to false. * + * [--eighty=] + * : 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456 + * + * [--eighty-one=] + * : 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 + * + * [--forty=] + * : 123456789 123456789 123456789 123456 + * + * [--forty-one=] + * : 123456789 123456789 123456789 1234567 + * * ## EXAMPLES * * # Re-generate only the thumbnails of "large" image size for all images. @@ -252,6 +277,14 @@ Feature: Get help about WP-CLI commands * 3/3 Regenerated "large" thumbnail for "Even Yooger than the Yoogest Image Ever, Really" (ID 9997). * Success: Regenerated 3 of 3 images. * + * # 6 initial spaces + 74 = 80; 6 + 75 = 81 + * # 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234 + * # 123456789 123456789 123456789 123456789 123456789 123456789 123456789 12345 + * + * # 6 initial spaces + 34 = 40; 6 + 35 = 41 + * # 123456789 123456789 123456789 1234 + * # 123456789 123456789 123456789 12345 + * */ function my_command() {} } @@ -262,11 +295,29 @@ Feature: Get help about WP-CLI commands When I run `wp help test-wordwrap my_command` Then STDOUT should contain: + """ + 123456789 123456789 123456789 123456789 123456789 123456789 123456789 12345678 + + """ + And STDOUT should contain: """ [--skip-delete] Skip deletion of the original thumbnails. If your thumbnails are linked from - sources outside your control, it's likely best to leave them around. Defaults to - false. + sources outside your control, it's likely best to leave them around. + Defaults to false. + + """ + And STDOUT should contain: + """ + [--eighty=] + 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456 + + """ + And STDOUT should contain: + """ + [--eighty-one=] + 123456789 123456789 123456789 123456789 123456789 123456789 123456789 + 1234567 """ And STDOUT should contain: @@ -284,6 +335,12 @@ Feature: Get help about WP-CLI commands Success: Regenerated 3 of 3 images. """ + And STDOUT should contain: + """ + # 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234 + # 123456789 123456789 123456789 123456789 123456789 123456789 123456789 + 12345 + """ And STDOUT should contain: """ --url= @@ -291,56 +348,91 @@ Feature: Get help about WP-CLI commands the target site is specified. """ + And STDERR should be empty - When I run `WP_CLI_HELP_WORDWRAP_WIDTH=30 wp help test-wordwrap my_command` + When I run `wp help test-wordwrap my_command | wc -L` + Then STDOUT should be: + """ + 80 + """ + + When I run `TERM=vt100 COLUMNS=40 wp help test-wordwrap my_command` Then STDOUT should contain: + """ + 123456789 123456789 123456789 + 123456789 123456789 123456789 + 123456789 12345678 + + """ + And STDOUT should contain: """ [--skip-delete] - Skip deletion of the - original thumbnails. If your - thumbnails are linked from - sources outside your control, - it's likely best to leave them - around. Defaults to false. + Skip deletion of the original + thumbnails. If your thumbnails are + linked from sources outside your + control, it's likely best to leave + them around. Defaults to false. + + """ + And STDOUT should contain: + """ + [--forty=] + 123456789 123456789 123456789 123456 + + """ + And STDOUT should contain: + """ + [--forty-one=] + 123456789 123456789 123456789 + 1234567 """ And STDOUT should contain: """ - # Re-generate only the - thumbnails of "large" image - size for all images. + # Re-generate only the thumbnails of + "large" image size for all images. $ wp media regenerate --image_size=large - Do you really want to - regenerate the "large" image - size for all images? [y/n] y - Found 3 images to - regenerate. - 1/3 Regenerated "large" - thumbnail for "Yoogest Image - Ever, Really" (ID 9999). + Do you really want to regenerate the + "large" image size for all images? + [y/n] y + Found 3 images to regenerate. + 1/3 Regenerated "large" thumbnail + for "Yoogest Image Ever, Really" (ID + 9999). 2/3 No "large" thumbnail - regeneration needed for - "Snowflake" (ID 9998). - 3/3 Regenerated "large" - thumbnail for "Even Yooger - than the Yoogest Image Ever, - Really" (ID 9997). - Success: Regenerated 3 of - 3 images. + regeneration needed for "Snowflake" + (ID 9998). + 3/3 Regenerated "large" thumbnail + for "Even Yooger than the Yoogest + Image Ever, Really" (ID 9997). + Success: Regenerated 3 of 3 images. """ + And STDOUT should contain: + """ + # 123456789 123456789 123456789 1234 + # 123456789 123456789 123456789 + 12345 + """ And STDOUT should contain: """ --url= - Pretend request came - from given URL. In multisite, - this argument is how the - target site is specified. + Pretend request came from given + URL. In multisite, this argument + is how the target site is + specified. + + """ + And STDERR should be empty + When I run `TERM=vt100 COLUMNS=40 wp help test-wordwrap my_command | wc -L` + Then STDOUT should be: + """ + 40 """ - When I run `WP_CLI_HELP_WORDWRAP_WIDTH=0 wp help test-wordwrap my_command` + When I run `TERM=vt100 COLUMNS=1000 wp help test-wordwrap my_command` Then STDOUT should contain: """ [--skip-delete] @@ -365,3 +457,116 @@ Feature: Get help about WP-CLI commands Pretend request came from given URL. In multisite, this argument is how the target site is specified. """ + And STDERR should be empty + + Scenario: Help for commands with subcommands should wordwrap well + Given a WP install + And a wp-content/plugins/test-cli/command.php file: + """ + get_longdesc(); // definition lists @@ -66,22 +75,36 @@ private static function show_help( $command ) { // Ensure all non-section headers are indented. $out = preg_replace( '#^([^\s^\#])#m', "\t$1", $out ); + $tab = str_repeat( ' ', 2 ); + + // Need to de-tab for wordwrapping to work properly. + $out = str_replace( "\t", $tab, $out ); + + $wordwrap_width = \cli\Shell::columns(); + // Wordwrap with indent. - $wordwrap_width = 80; - if ( false !== ( $env_wordwrap_width = getenv( 'WP_CLI_HELP_WORDWRAP_WIDTH' ) ) ) { - $wordwrap_width = (int) $env_wordwrap_width; - } - if ( $wordwrap_width > 0 ) { - $out = preg_replace_callback( '/([ \t]*)[^\n]+\n/', function ( $matches ) use ( $wordwrap_width ) { - return wordwrap( $matches[0], $wordwrap_width, "\n{$matches[1]}" ); - }, $out ); + $out = preg_replace_callback( '/^( *)([^\n]+)\n/m', function ( $matches ) use ( $wordwrap_width ) { + return $matches[1] . str_replace( "\n", "\n{$matches[1]}", wordwrap( $matches[2], $wordwrap_width - strlen( $matches[1] ) ) ) . "\n"; + }, $out ); + + if ( $subcommands ) { + // Wordwrap with column indent. + $subcommands = preg_replace_callback( '/^(' . $column_subpattern . ')([^\n]+)\n/m', function ( $matches ) use ( $wordwrap_width, $tab ) { + // Need to de-tab for wordwrapping to work properly. + $matches[1] = str_replace( "\t", $tab, $matches[1] ); + $matches[2] = str_replace( "\t", $tab, $matches[2] ); + $padding_len = strlen( $matches[1] ); + $padding = str_repeat( ' ', $padding_len ); + return $matches[1] . str_replace( "\n", "\n$padding", wordwrap( $matches[2], $wordwrap_width - $padding_len ) ) . "\n"; + }, $subcommands ); + + // Put subcommands back. + $out = str_replace( $subcommands_header, $subcommands, $out ); } // section headers $out = preg_replace( '/^## ([A-Z ]+)/m', WP_CLI::colorize( '%9\1%n' ), $out ); - $out = str_replace( "\t", ' ', $out ); - self::pass_through_pager( $out ); } diff --git a/templates/man-params.mustache b/templates/man-params.mustache index d2786014e6..dcf83d419d 100644 --- a/templates/man-params.mustache +++ b/templates/man-params.mustache @@ -15,4 +15,5 @@ {{/parameters}} {{#root_command}} Run 'wp help ' to get more information on a specific command. + {{/root_command}}