Then STDOUT should be a table containing rows:
| name | status | update | version |
| p2 | active | available | 1.4.1 |
+
+ Scenario: Get details about an installed theme
+ Given a WP install
+
+ When I run `wp theme install twentyeleven`
+ Then STDOUT should not be empty
+
+ When I run `wp theme get twentyeleven`
+ Then STDOUT should be a table containing rows:
+ | Field | Value |
+ | name | Twenty Eleven |
}
/**
+ * Get a theme
+ *
+ * ## OPTIONS
+ *
+ * <theme>
+ * : The theme to get.
+ *
+ * * --format=<format>
+ * : The format to use when printing the theme, acceptable values:
+ *
+ * - **table**: Outputs all fields of the theme as a table.
+ *
+ * - **json**: Outputs all fields in JSON format.
+ *
+ * ## EXAMPLES
+ *
+ * wp theme get twentytwelve
+ *
+ * @synopsis <theme> [--format=<format>]
+ */
+ public function get( $args, $assoc_args ) {
+
+ $defaults = array(
+ 'format' => 'table'
+ );
+ $assoc_args = array_merge( $defaults, $assoc_args );
+
+ $theme = $this->parse_name( $args[0] );
+
+ // WP_Theme object employs magic getter, unfortunately
+ $theme_vars = array( 'name', 'title', 'version', 'parent_theme', 'template_dir', 'stylesheet_dir', 'template', 'stylesheet', 'screenshot', 'description', 'author', 'tags', 'theme_root', 'theme_root_uri',
+ );
+ $theme_obj = new stdClass;
+ foreach( $theme_vars as $var ) {
+ $theme_obj->$var = $theme->$var;
+ }
+
+ switch ( $assoc_args['format'] ) {
+
+ case 'table':
+ unset( $theme_obj->tags );
+ $fields = get_object_vars( $theme_obj );
+ \WP_CLI\Utils\assoc_array_to_table( $fields );
+ break;
+
+ case 'json':
+ WP_CLI::print_value( $theme_obj, $assoc_args );
+ break;
+
+ default:
+ \WP_CLI::error( "Invalid format: " . $assoc_args['format'] );
+ break;
+ }
+ }
+
+ /**
* Update a theme.
*
* ## OPTIONS
}
/**
+ * Format an associative array as a table
+ *
+ * @param array $fields Fields and values to format
+ */
+function assoc_array_to_table( $fields ) {
+ $rows = array();
+
+ foreach ( $fields as $field => $value ) {
+ if ( !is_string($value) ) {
+ $value = json_encode( $value );
+ }
+
+ $rows[] = (object) array(
+ 'Field' => $field,
+ 'Value' => $value
+ );
+ }
+
+ format_items( 'table', $rows, array( 'Field', 'Value' ) );
+}
+
+/**
* Write data as CSV to a given file.
*
* @param resource $fd File descriptor