-
Notifications
You must be signed in to change notification settings - Fork 357
feat(cli): add search and list commands #2154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /****************************************************************************** | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation. | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Eclipse Public License 2.0 which is available at | ||
| * https://www.eclipse.org/legal/epl-2.0. | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| *****************************************************************************/ | ||
|
|
||
| import { RegistryOptions } from './registry-options'; | ||
|
|
||
| export interface ListOptions extends RegistryOptions { | ||
| /** | ||
| * Namespace whose extensions should be listed. | ||
| */ | ||
| namespace: string; | ||
| /** | ||
| * Print the raw namespace metadata as JSON instead of a list. | ||
| */ | ||
| json?: boolean; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /****************************************************************************** | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation. | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Eclipse Public License 2.0 which is available at | ||
| * https://www.eclipse.org/legal/epl-2.0. | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| *****************************************************************************/ | ||
|
|
||
| import { ListOptions } from './list-options'; | ||
| import { Registry } from './registry'; | ||
| import { formatCount } from './table'; | ||
| import { addEnvOptions } from './util'; | ||
|
|
||
| /** | ||
| * Lists the extensions published in a namespace. | ||
| */ | ||
| export async function list(options: ListOptions): Promise<void> { | ||
| addEnvOptions(options); | ||
| const registry = new Registry(options); | ||
| const namespace = await registry.getNamespace(options.namespace); | ||
| if (namespace.error) { | ||
| throw new Error(namespace.error); | ||
| } | ||
|
|
||
| if (options.json) { | ||
| console.log(JSON.stringify(namespace, null, 4)); | ||
| return; | ||
| } | ||
|
|
||
| // Sorted here rather than relying on the response's key order, so the output is stable and | ||
| // scriptable regardless of how the registry happens to serialise the map. | ||
| const names = Object.keys(namespace.extensions ?? {}).sort((a, b) => a.localeCompare(b)); | ||
| const verified = namespace.verified ? ' (verified)' : ''; | ||
| console.log(`${namespace.name}${verified} - ${formatCount(names.length, 'extension')}`); | ||
| if (names.length === 0) { | ||
| return; | ||
| } | ||
|
|
||
| console.log(); | ||
| for (const name of names) { | ||
| console.log(` ${namespace.name}.${name}`); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /****************************************************************************** | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation. | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Eclipse Public License 2.0 which is available at | ||
| * https://www.eclipse.org/legal/epl-2.0. | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| *****************************************************************************/ | ||
|
|
||
| import { RegistryOptions } from './registry-options'; | ||
|
|
||
| export interface SearchOptions extends RegistryOptions { | ||
| /** | ||
| * Text to search for. Omit to browse, which is what makes `--category` useful on its own. | ||
| */ | ||
| text?: string; | ||
| /** | ||
| * Restrict results to a category, e.g. `Programming Languages`. | ||
| */ | ||
| category?: string; | ||
| /** | ||
| * Restrict results to extensions published for a target platform. | ||
| */ | ||
| target?: string; | ||
| /** | ||
| * Sort key: `relevance`, `timestamp`, `rating` or `downloadCount`. | ||
| */ | ||
| sortBy?: string; | ||
| /** | ||
| * `asc` or `desc`. | ||
| */ | ||
| sortOrder?: string; | ||
| /** | ||
| * Number of results to return. | ||
| */ | ||
| size?: number; | ||
| /** | ||
| * Index of the first result, for paging through a large result set. | ||
| */ | ||
| offset?: number; | ||
| /** | ||
| * Print the raw results as JSON instead of a table. | ||
| */ | ||
| json?: boolean; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /****************************************************************************** | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation. | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Eclipse Public License 2.0 which is available at | ||
| * https://www.eclipse.org/legal/epl-2.0. | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| *****************************************************************************/ | ||
|
|
||
| import { Registry, SearchEntry } from './registry'; | ||
| import { SearchOptions } from './search-options'; | ||
| import { formatNumber, printRows, truncate } from './table'; | ||
| import { addEnvOptions } from './util'; | ||
|
|
||
| /** Sort keys the registry accepts, for an up-front check with a better message than a 400. */ | ||
| export const SORT_KEYS = ['relevance', 'timestamp', 'rating', 'downloadCount']; | ||
|
|
||
| export const SORT_ORDERS = ['asc', 'desc']; | ||
|
|
||
| export const DEFAULT_SEARCH_SIZE = 20; | ||
|
|
||
| /** Keeps a row from wrapping on a normal terminal, where the other columns take about half of it. */ | ||
| const DESCRIPTION_WIDTH = 60; | ||
|
|
||
| /** | ||
| * Searches the registry for extensions. | ||
| */ | ||
| export async function search(options: SearchOptions): Promise<void> { | ||
| addEnvOptions(options); | ||
| if (options.sortBy && !SORT_KEYS.includes(options.sortBy)) { | ||
| throw new Error(`Sort key must be one of ${SORT_KEYS.join(', ')}.`); | ||
| } | ||
| if (options.sortOrder && !SORT_ORDERS.includes(options.sortOrder)) { | ||
| throw new Error(`Sort order must be one of ${SORT_ORDERS.join(', ')}.`); | ||
| } | ||
|
|
||
| const size = options.size ?? DEFAULT_SEARCH_SIZE; | ||
| const offset = options.offset ?? 0; | ||
| const registry = new Registry(options); | ||
| const result = await registry.search({ | ||
| query: options.text, | ||
| category: options.category, | ||
| targetPlatform: options.target, | ||
| sortBy: options.sortBy, | ||
| sortOrder: options.sortOrder, | ||
| size, | ||
| offset | ||
| }); | ||
| if (result.error) { | ||
| throw new Error(result.error); | ||
| } | ||
|
|
||
| if (options.json) { | ||
| console.log(JSON.stringify(result, null, 4)); | ||
| return; | ||
| } | ||
|
|
||
| printResults(result.extensions ?? [], result.totalSize, offset); | ||
| } | ||
|
|
||
| function printResults(entries: SearchEntry[], totalSize: number, offset: number): void { | ||
| if (entries.length === 0) { | ||
| console.log('No extensions found.'); | ||
| return; | ||
| } | ||
|
|
||
| const rows = entries.map(entry => [ | ||
| `${entry.namespace}.${entry.name}`, | ||
| entry.version, | ||
| formatNumber(entry.downloadCount), | ||
| entry.averageRating !== undefined ? entry.averageRating.toFixed(1) : '-', | ||
| describe(entry) | ||
| ]); | ||
| printRows([['Extension', 'Version', 'Downloads', 'Rating', 'Description'], ...rows]); | ||
|
|
||
| const last = offset + entries.length; | ||
| console.log(); | ||
| console.log(`Showing ${offset + 1}-${last} of ${formatNumber(totalSize)}.`); | ||
| if (last < totalSize) { | ||
| console.log(`Pass --offset ${last} for the next page.`); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The description, prefixed with anything a reader should weigh before installing. Deprecation is | ||
| * the one flag worth spending row width on here; `show` reports the rest. | ||
| */ | ||
| function describe(entry: SearchEntry): string { | ||
| const description = truncate(entry.description ?? '', DESCRIPTION_WIDTH); | ||
| return entry.deprecated ? `(deprecated) ${description}`.trimEnd() : description; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.