From bed5cb0b47e650000a69232b81e45c01b433dc2b Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Sat, 20 Apr 2013 21:27:00 -0700 Subject: [PATCH] Improvements to `wp term` output * Add `--porcelain` argument to `wp term create` * `wp term create` should include term ID in success message * `wp term delete` includes the term ID of the deleted term * Updated tests / doc See https://github.com/wp-cli/wp-cli/issues/399#issuecomment-16685216 --- features/term.feature | 25 ++++++++++++++++++++----- man-src/term-create.txt | 4 ++++ man/term-create.1 | 8 +++++++- php/commands/term.php | 20 +++++++++++++++----- 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/features/term.feature b/features/term.feature index e8be1655..47a4219d 100644 --- a/features/term.feature +++ b/features/term.feature @@ -3,12 +3,9 @@ Feature: Manage WordPress terms Scenario: Creating/listing a term Given a WP install - When I run `wp term create 'Test term' post_tag --slug=test --description='This is a test term'` + When I run `wp term create 'Test term' post_tag --slug=test --description='This is a test term' --porcelain` Then it should run without errors - And STDOUT should be: - """ - Success: Term created. - """ + And STDOUT should match '%d' When I run the previous command again Then STDERR should not be empty @@ -19,3 +16,21 @@ Feature: Manage WordPress terms """ [{"name":"Test term","slug":"test","description":"This is a test term","parent":"0","count":"0"}] """ + + Scenario: Creating/deleting a term + Given a WP install + + When I run `wp term create 'Test delete term' post_tag --slug=test-delete --description='This is a test term to be deleted' --porcelain` + Then it should run without errors + And STDOUT should match '%d' + And save STDOUT as {TERM_ID} + + When I run `wp term delete {TERM_ID} post_tag` + Then it should run without errors + And STDOUT should contain: + """ + Deleted post_tag {TERM_ID}. + """ + + When I run the previous command again + Then STDERR should not be empty diff --git a/man-src/term-create.txt b/man-src/term-create.txt index e34cd384..46b85b9f 100644 --- a/man-src/term-create.txt +++ b/man-src/term-create.txt @@ -20,6 +20,10 @@ A parent for the new term. +* `--porcelain`: + + Output just the new term id. + ## EXAMPLES wp term create Apple category --description="A type of fruit" diff --git a/man/term-create.1 b/man/term-create.1 index a5cf4ad5..366ee1a8 100644 --- a/man/term-create.1 +++ b/man/term-create.1 @@ -7,7 +7,7 @@ \fBwp\-term\-create\fR \- Create a term\. . .SH "SYNOPSIS" -wp term create \fIterm\fR \fItaxonomy\fR [\-\-slug=\fIslug\fR] [\-\-description=\fIdescription\fR] [\-\-parent=\fIterm\-id\fR] +wp term create \fIterm\fR \fItaxonomy\fR [\-\-slug=\fIslug\fR] [\-\-description=\fIdescription\fR] [\-\-parent=\fIterm\-id\fR] [\-\-porcelain] . .SH "OPTIONS" . @@ -41,6 +41,12 @@ A description for the new term\. .IP A parent for the new term\. . +.TP +\fB\-\-porcelain\fR: +. +.IP +Output just the new term id\. +. .SH "EXAMPLES" . .nf diff --git a/php/commands/term.php b/php/commands/term.php index c55b5850..12e56bda 100644 --- a/php/commands/term.php +++ b/php/commands/term.php @@ -43,7 +43,7 @@ class Term_Command extends WP_CLI_Command { /** * Create a term. * - * @synopsis [--slug=] [--description=] [--parent=] + * @synopsis [--slug=] [--description=] [--parent=] [--porcelain] */ public function create( $args, $assoc_args ) { @@ -56,12 +56,22 @@ class Term_Command extends WP_CLI_Command { ); $assoc_args = wp_parse_args( $assoc_args, $defaults ); + if ( isset( $assoc_args['porcelain'] ) ) { + $porcelain = true; + unset( $assoc_args['porcelain'] ); + } else + $porcelain = false; + $ret = wp_insert_term( $term, $taxonomy, $assoc_args ); if ( is_wp_error( $ret ) ) WP_CLI::error( $ret->get_error_message() ); - else - WP_CLI::success( "Term created." ); + else { + if ( $porcelain ) + WP_CLI::line( $ret['term_id'] ); + else + WP_CLI::success( sprintf( "Created %s %d.", $taxonomy, $ret['term_id'] ) ); + } } /** @@ -108,9 +118,9 @@ class Term_Command extends WP_CLI_Command { if ( is_wp_error( $ret ) ) WP_CLI::error( $ret->get_error_message() ); else if ( $ret ) - WP_CLI::success( "Term deleted." ); + WP_CLI::success( sprintf( "Deleted %s %d.", $taxonomy, $term_id ) ); else - WP_CLI::error( "Error deleting term." ); + WP_CLI::error( "Term doesn't exist." ); } } -- 2.11.0