Skip to content

Commit 959765d

Browse files
swissspidyclaude
andauthored
Add connector ID field to list and get commands (#25)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent bd62752 commit 959765d

3 files changed

Lines changed: 57 additions & 54 deletions

File tree

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ wp connectors get <connector> [--fields=<fields>] [--format=<format>]
276276
+-----------------+-----------------------------------------------+
277277
| Field | Value |
278278
+-----------------+-----------------------------------------------+
279+
| id | openai |
279280
| name | OpenAI |
280281
| description | Text and image generation with GPT and Dall-E |
281282
| status | connected |
@@ -323,13 +324,13 @@ wp connectors list [--status=<status>] [--fields=<fields>] [--format=<format>]
323324

324325
# List all connectors
325326
$ wp connectors list
326-
+-----------+-----------------------------------------------+---------------+
327-
| name | description | status |
328-
+-----------+-----------------------------------------------+---------------+
329-
| Anthropic | Text generation with Claude. | not installed |
330-
| Google | Text and image generation with Gemini... | not installed |
331-
| OpenAI | Text and image generation with GPT and Dall-E | connected |
332-
+-----------+-----------------------------------------------+---------------+
327+
+-----------+-----------+-----------------------------------------------+---------------+
328+
| id | name | description | status |
329+
+-----------+-----------+-----------------------------------------------+---------------+
330+
| anthropic | Anthropic | Text generation with Claude. | not installed |
331+
| google | Google | Text and image generation with Gemini... | not installed |
332+
| openai | OpenAI | Text and image generation with GPT and Dall-E | connected |
333+
+-----------+-----------+-----------------------------------------------+---------------+
333334

334335
# List only connected connectors
335336
$ wp connectors list --status=connected

features/connectors.feature

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ Feature: List and get AI connectors
1616
Scenario: List connectors returns built-in providers with descriptions
1717
When I run `wp connectors list --format=json`
1818
Then STDOUT should contain:
19+
"""
20+
"id":"openai"
21+
"""
22+
And STDOUT should contain:
1923
"""
2024
"name":"OpenAI"
2125
"""
@@ -49,32 +53,12 @@ Feature: List and get AI connectors
4953
"""
5054

5155
@require-wp-7.0
52-
Scenario: List connectors in table format shows name, description and status columns
56+
Scenario: List connectors in table format shows id, name, description and status columns
5357
When I run `wp connectors list`
54-
Then STDOUT should contain:
55-
"""
56-
name
57-
"""
58-
And STDOUT should contain:
59-
"""
60-
description
61-
"""
62-
And STDOUT should contain:
63-
"""
64-
status
65-
"""
66-
And STDOUT should contain:
67-
"""
68-
OpenAI
69-
"""
70-
And STDOUT should contain:
71-
"""
72-
Anthropic
73-
"""
74-
And STDOUT should contain:
75-
"""
76-
Google
77-
"""
58+
Then STDOUT should match /^id\tname\tdescription\tstatus$/m
59+
And STDOUT should match /^anthropic\tAnthropic\t/m
60+
And STDOUT should match /^google\tGoogle\t/m
61+
And STDOUT should match /^openai\tOpenAI\t/m
7862

7963
@require-wp-7.0
8064
Scenario: List connectors supports --status filter
@@ -91,25 +75,17 @@ Feature: List and get AI connectors
9175
@require-wp-7.0
9276
Scenario: Get a specific connector shows key-value layout
9377
When I run `wp connectors get openai`
94-
Then STDOUT should contain:
95-
"""
96-
name
97-
"""
98-
And STDOUT should contain:
99-
"""
100-
OpenAI
101-
"""
102-
And STDOUT should contain:
103-
"""
104-
status
105-
"""
78+
Then STDOUT should match /^Field\tValue$/m
79+
And STDOUT should match /^id\topenai$/m
80+
And STDOUT should match /^name\tOpenAI$/m
81+
And STDOUT should match /^status\t/m
10682

10783
@require-wp-7.0
10884
Scenario: Get a specific connector in JSON format
10985
When I run `wp connectors get openai --format=json`
11086
Then STDOUT should be JSON containing:
11187
"""
112-
{"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":""}
88+
{"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":""}
11389
"""
11490

11591
# TODO: Depends on https://core.trac.wordpress.org/ticket/64819.
@@ -143,6 +119,29 @@ Feature: List and get AI connectors
143119
{"name":"OpenAI","auth_method":"api_key","type":"ai_provider","plugin_file":"ai-provider-for-openai/plugin.php"}
144120
"""
145121

122+
@require-wp-7.0
123+
Scenario: Connector ID from list can be passed to get
124+
When I run `wp connectors list --fields=id --format=json`
125+
Then STDOUT should contain:
126+
"""
127+
{"id":"openai"}
128+
"""
129+
And STDOUT should contain:
130+
"""
131+
{"id":"anthropic"}
132+
"""
133+
And STDOUT should contain:
134+
"""
135+
{"id":"google"}
136+
"""
137+
And save STDOUT '"id":"([a-z0-9_-]+)"' as {CONNECTOR_ID}
138+
139+
When I run `wp connectors get {CONNECTOR_ID} --fields=id --format=json`
140+
Then STDOUT should be JSON containing:
141+
"""
142+
{"id":"{CONNECTOR_ID}"}
143+
"""
144+
146145
@require-wp-7.0
147146
Scenario: Error on non-existent connector
148147
When I try `wp connectors get nonexistent`

src/Connectors_Command.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Connectors_Command extends WP_CLI_Command {
2323
* @var string[]
2424
*/
2525
protected $default_fields = [
26+
'id',
2627
'name',
2728
'description',
2829
'status',
@@ -61,13 +62,13 @@ class Connectors_Command extends WP_CLI_Command {
6162
*
6263
* # List all connectors
6364
* $ wp connectors list
64-
* +-----------+-----------------------------------------------+---------------+
65-
* | name | description | status |
66-
* +-----------+-----------------------------------------------+---------------+
67-
* | Anthropic | Text generation with Claude. | not installed |
68-
* | Google | Text and image generation with Gemini... | not installed |
69-
* | OpenAI | Text and image generation with GPT and Dall-E | connected |
70-
* +-----------+-----------------------------------------------+---------------+
65+
* +-----------+-----------+-----------------------------------------------+---------------+
66+
* | id | name | description | status |
67+
* +-----------+-----------+-----------------------------------------------+---------------+
68+
* | anthropic | Anthropic | Text generation with Claude. | not installed |
69+
* | google | Google | Text and image generation with Gemini... | not installed |
70+
* | openai | OpenAI | Text and image generation with GPT and Dall-E | connected |
71+
* +-----------+-----------+-----------------------------------------------+---------------+
7172
*
7273
* # List only connected connectors
7374
* $ wp connectors list --status=connected
@@ -141,6 +142,7 @@ static function ( array $item ) use ( $status_filter ) {
141142
* +-----------------+-----------------------------------------------+
142143
* | Field | Value |
143144
* +-----------------+-----------------------------------------------+
145+
* | id | openai |
144146
* | name | OpenAI |
145147
* | description | Text and image generation with GPT and Dall-E |
146148
* | status | connected |
@@ -180,7 +182,7 @@ public function get( $args, $assoc_args ) {
180182

181183
$item['api_key'] = $api_key;
182184

183-
$default_fields = array( 'name', 'description', 'status', 'credentials_url', 'api_key' );
185+
$default_fields = array( 'id', 'name', 'description', 'status', 'credentials_url', 'api_key' );
184186
$formatter = new \WP_CLI\Formatter( $assoc_args, $default_fields );
185187
$formatter->display_item( $item );
186188
}
@@ -190,14 +192,15 @@ public function get( $args, $assoc_args ) {
190192
*
191193
* @param string $connector_id The connector ID.
192194
* @param mixed[] $connector Connector settings from wp_get_connectors().
193-
* @return array{name: string, description: string, status: string, type: string, auth_method: string, credentials_url: string, plugin_file: string}
195+
* @return array{id: string, name: string, description: string, status: string, type: string, auth_method: string, credentials_url: string, plugin_file: string}
194196
*/
195197
private function build_connector_item( string $connector_id, array $connector ): array {
196198
$auth = is_array( $connector['authentication'] ) ? $connector['authentication'] : array();
197199
$plugin = isset( $connector['plugin'] ) && is_array( $connector['plugin'] ) ? $connector['plugin'] : array();
198200
$plugin_file = isset( $plugin['file'] ) && is_string( $plugin['file'] ) ? $plugin['file'] : '';
199201

200202
return array(
203+
'id' => $connector_id,
201204
'name' => $this->scalar_to_string( $connector['name'] ?? '' ),
202205
'description' => $this->scalar_to_string( $connector['description'] ?? '' ),
203206
'status' => $this->get_connector_status( $connector_id, $connector ),

0 commit comments

Comments
 (0)