diff --git a/README.md b/README.md index d3e971ad..d2f4eccf 100644 --- a/README.md +++ b/README.md @@ -197,10 +197,28 @@ wp plugin get [--field=] [--fields=] [--format=] - yaml --- +**AVAILABLE FIELDS** + +These fields will be displayed by default for the plugin: + +* name +* title +* author +* version +* description +* status + +These fields are optionally available: + +* requires_wp +* requires_php +* requires_plugins + **EXAMPLES** + # Get plugin details. $ wp plugin get bbpress --format=json - {"name":"bbpress","title":"bbPress","author":"The bbPress Contributors","version":"2.6-alpha","description":"bbPress is forum software with a twist from the creators of WordPress.","status":"active"} + {"name":"bbpress","title":"bbPress","author":"The bbPress Contributors","version":"2.6.9","description":"bbPress is forum software with a twist from the creators of WordPress.","status":"active"} diff --git a/features/plugin-get.feature b/features/plugin-get.feature new file mode 100644 index 00000000..cdb3a75a --- /dev/null +++ b/features/plugin-get.feature @@ -0,0 +1,74 @@ +Feature: Get WordPress plugin + + Scenario: Get plugin info + Given a WP install + And a wp-content/plugins/foo.php file: + """ + /** + * Plugin Name: Sample Plugin + * Description: Description for sample plugin. + * Requires at least: 6.0 + * Requires PHP: 5.6 + * Version: 1.0.0 + * Author: John Doe + * Author URI: https://example.com/ + * License: GPLv2 or later + * License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * Text Domain: sample-plugin + */ + """ + + When I run `wp plugin get foo --fields=name,author,version,status` + Then STDOUT should be a table containing rows: + | Field | Value | + | name | foo | + | author | John Doe | + | version | 1.0.0 | + | status | inactive | + + When I run `wp plugin get foo --format=json` + Then STDOUT should be: + """ + {"name":"foo","title":"Sample Plugin","author":"John Doe","version":"1.0.0","description":"Description for sample plugin.","status":"inactive"} + """ + + @require-wp-6.5 + Scenario: Get Requires Plugins header of plugin + Given a WP install + And a wp-content/plugins/foo.php file: + """ + fetcher->get_check( $args[0] ); $file = $plugin->file; $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $file, false, false ); $plugin_obj = (object) [ - 'name' => Utils\get_plugin_name( $file ), - 'title' => $plugin_data['Name'], - 'author' => $plugin_data['Author'], - 'version' => $plugin_data['Version'], - 'description' => wordwrap( $plugin_data['Description'] ), - 'status' => $this->get_status( $file ), + 'name' => Utils\get_plugin_name( $file ), + 'title' => $plugin_data['Name'], + 'author' => $plugin_data['Author'], + 'version' => $plugin_data['Version'], + 'description' => wordwrap( $plugin_data['Description'] ), + 'status' => $this->get_status( $file ), + 'requires_wp' => ! empty( $plugin_data['RequiresWP'] ) ? $plugin_data['RequiresWP'] : '', + 'requires_php' => ! empty( $plugin_data['RequiresPHP'] ) ? $plugin_data['RequiresPHP'] : '', + 'requires_plugins' => ! empty( $plugin_data['RequiresPlugins'] ) ? $plugin_data['RequiresPlugins'] : '', ]; if ( empty( $assoc_args['fields'] ) ) { - $plugin_array = get_object_vars( $plugin_obj ); - $assoc_args['fields'] = array_keys( $plugin_array ); + $assoc_args['fields'] = $default_fields; } $formatter = $this->get_formatter( $assoc_args );