diff --git a/README.md b/README.md index 79e2043..2df28c8 100644 --- a/README.md +++ b/README.md @@ -276,6 +276,7 @@ wp connectors get [--fields=] [--format=] +-----------------+-----------------------------------------------+ | Field | Value | +-----------------+-----------------------------------------------+ + | id | openai | | name | OpenAI | | description | Text and image generation with GPT and Dall-E | | status | connected | @@ -323,13 +324,13 @@ wp connectors list [--status=] [--fields=] [--format=] # List all connectors $ wp connectors list - +-----------+-----------------------------------------------+---------------+ - | name | description | status | - +-----------+-----------------------------------------------+---------------+ - | Anthropic | Text generation with Claude. | not installed | - | Google | Text and image generation with Gemini... | not installed | - | OpenAI | Text and image generation with GPT and Dall-E | connected | - +-----------+-----------------------------------------------+---------------+ + +-----------+-----------+-----------------------------------------------+---------------+ + | id | name | description | status | + +-----------+-----------+-----------------------------------------------+---------------+ + | anthropic | Anthropic | Text generation with Claude. | not installed | + | google | Google | Text and image generation with Gemini... | not installed | + | openai | OpenAI | Text and image generation with GPT and Dall-E | connected | + +-----------+-----------+-----------------------------------------------+---------------+ # List only connected connectors $ wp connectors list --status=connected diff --git a/features/connectors.feature b/features/connectors.feature index b18e489..e65f985 100644 --- a/features/connectors.feature +++ b/features/connectors.feature @@ -16,6 +16,10 @@ Feature: List and get AI connectors Scenario: List connectors returns built-in providers with descriptions When I run `wp connectors list --format=json` Then STDOUT should contain: + """ + "id":"openai" + """ + And STDOUT should contain: """ "name":"OpenAI" """ @@ -49,32 +53,12 @@ Feature: List and get AI connectors """ @require-wp-7.0 - Scenario: List connectors in table format shows name, description and status columns + Scenario: List connectors in table format shows id, name, description and status columns When I run `wp connectors list` - Then STDOUT should contain: - """ - name - """ - And STDOUT should contain: - """ - description - """ - And STDOUT should contain: - """ - status - """ - And STDOUT should contain: - """ - OpenAI - """ - And STDOUT should contain: - """ - Anthropic - """ - And STDOUT should contain: - """ - Google - """ + Then STDOUT should match /^id\tname\tdescription\tstatus$/m + And STDOUT should match /^anthropic\tAnthropic\t/m + And STDOUT should match /^google\tGoogle\t/m + And STDOUT should match /^openai\tOpenAI\t/m @require-wp-7.0 Scenario: List connectors supports --status filter @@ -91,25 +75,17 @@ Feature: List and get AI connectors @require-wp-7.0 Scenario: Get a specific connector shows key-value layout When I run `wp connectors get openai` - Then STDOUT should contain: - """ - name - """ - And STDOUT should contain: - """ - OpenAI - """ - And STDOUT should contain: - """ - status - """ + Then STDOUT should match /^Field\tValue$/m + And STDOUT should match /^id\topenai$/m + And STDOUT should match /^name\tOpenAI$/m + And STDOUT should match /^status\t/m @require-wp-7.0 Scenario: Get a specific connector in JSON format When I run `wp connectors get openai --format=json` Then STDOUT should be JSON containing: """ - {"name":"OpenAI","description":"Text and image generation with GPT and Dall-E.","status":"not installed","credentials_url":"https://platform.openai.com/api-keys","api_key":""} + {"id":"openai","name":"OpenAI","description":"Text and image generation with GPT and Dall-E.","status":"not installed","credentials_url":"https://platform.openai.com/api-keys","api_key":""} """ # TODO: Depends on https://core.trac.wordpress.org/ticket/64819. @@ -143,6 +119,29 @@ Feature: List and get AI connectors {"name":"OpenAI","auth_method":"api_key","type":"ai_provider","plugin_file":"ai-provider-for-openai/plugin.php"} """ + @require-wp-7.0 + Scenario: Connector ID from list can be passed to get + When I run `wp connectors list --fields=id --format=json` + Then STDOUT should contain: + """ + {"id":"openai"} + """ + And STDOUT should contain: + """ + {"id":"anthropic"} + """ + And STDOUT should contain: + """ + {"id":"google"} + """ + And save STDOUT '"id":"([a-z0-9_-]+)"' as {CONNECTOR_ID} + + When I run `wp connectors get {CONNECTOR_ID} --fields=id --format=json` + Then STDOUT should be JSON containing: + """ + {"id":"{CONNECTOR_ID}"} + """ + @require-wp-7.0 Scenario: Error on non-existent connector When I try `wp connectors get nonexistent` diff --git a/src/Connectors_Command.php b/src/Connectors_Command.php index 2a3e33c..4889626 100644 --- a/src/Connectors_Command.php +++ b/src/Connectors_Command.php @@ -23,6 +23,7 @@ class Connectors_Command extends WP_CLI_Command { * @var string[] */ protected $default_fields = [ + 'id', 'name', 'description', 'status', @@ -61,13 +62,13 @@ class Connectors_Command extends WP_CLI_Command { * * # List all connectors * $ wp connectors list - * +-----------+-----------------------------------------------+---------------+ - * | name | description | status | - * +-----------+-----------------------------------------------+---------------+ - * | Anthropic | Text generation with Claude. | not installed | - * | Google | Text and image generation with Gemini... | not installed | - * | OpenAI | Text and image generation with GPT and Dall-E | connected | - * +-----------+-----------------------------------------------+---------------+ + * +-----------+-----------+-----------------------------------------------+---------------+ + * | id | name | description | status | + * +-----------+-----------+-----------------------------------------------+---------------+ + * | anthropic | Anthropic | Text generation with Claude. | not installed | + * | google | Google | Text and image generation with Gemini... | not installed | + * | openai | OpenAI | Text and image generation with GPT and Dall-E | connected | + * +-----------+-----------+-----------------------------------------------+---------------+ * * # List only connected connectors * $ wp connectors list --status=connected @@ -141,6 +142,7 @@ static function ( array $item ) use ( $status_filter ) { * +-----------------+-----------------------------------------------+ * | Field | Value | * +-----------------+-----------------------------------------------+ + * | id | openai | * | name | OpenAI | * | description | Text and image generation with GPT and Dall-E | * | status | connected | @@ -180,7 +182,7 @@ public function get( $args, $assoc_args ) { $item['api_key'] = $api_key; - $default_fields = array( 'name', 'description', 'status', 'credentials_url', 'api_key' ); + $default_fields = array( 'id', 'name', 'description', 'status', 'credentials_url', 'api_key' ); $formatter = new \WP_CLI\Formatter( $assoc_args, $default_fields ); $formatter->display_item( $item ); } @@ -190,7 +192,7 @@ public function get( $args, $assoc_args ) { * * @param string $connector_id The connector ID. * @param mixed[] $connector Connector settings from wp_get_connectors(). - * @return array{name: string, description: string, status: string, type: string, auth_method: string, credentials_url: string, plugin_file: string} + * @return array{id: string, name: string, description: string, status: string, type: string, auth_method: string, credentials_url: string, plugin_file: string} */ private function build_connector_item( string $connector_id, array $connector ): array { $auth = is_array( $connector['authentication'] ) ? $connector['authentication'] : array(); @@ -198,6 +200,7 @@ private function build_connector_item( string $connector_id, array $connector ): $plugin_file = isset( $plugin['file'] ) && is_string( $plugin['file'] ) ? $plugin['file'] : ''; return array( + 'id' => $connector_id, 'name' => $this->scalar_to_string( $connector['name'] ?? '' ), 'description' => $this->scalar_to_string( $connector['description'] ?? '' ), 'status' => $this->get_connector_status( $connector_id, $connector ),