OSDN Git Service

site list: add --format=url; see #661
authorscribu <mail@scribu.net>
Tue, 13 Aug 2013 00:13:16 +0000 (03:13 +0300)
committerscribu <mail@scribu.net>
Tue, 13 Aug 2013 00:13:18 +0000 (03:13 +0300)
php/commands/site.php

index e34fce8..285c37c 100644 (file)
@@ -331,12 +331,12 @@ class Site_Command extends WP_CLI_Command {
         * : Comma-separated list of fields to show.
         *
         * --format=<format>
-        * : Output list as table, CSV, JSON. Defaults to table.
+        * : Output list as table, csv, json or url. Defaults to table.
         *
         * ## EXAMPLES
         *
         *     # Output the list of site URLs
-        *     wp site list --fields=domain,path --format=csv | tail -n +2 | sed 's/,//'
+        *     wp site list --format=url
         *
         * @subcommand list
         * @synopsis [--network=<id>] [--format=<format>] [--fields=<fields>]
@@ -365,7 +365,13 @@ class Site_Command extends WP_CLI_Command {
                );
                $it = new \WP_CLI\Iterators\Table( $iterator_args );
 
-               WP_CLI\Utils\format_items( $assoc_args['format'], $it, $assoc_args['fields'] );
+               if ( 'url' == $assoc_args['format'] ) {
+                       foreach ( $it as $blog ) {
+                               WP_CLI::line( $blog->domain . $blog->path );
+                       }
+               } else {
+                       WP_CLI\Utils\format_items( $assoc_args['format'], $it, $assoc_args['fields'] );
+               }
        }
 }