diff --git a/src/cli/src/index.ts b/src/cli/src/index.ts index 35c1dc7..9e1976f 100644 --- a/src/cli/src/index.ts +++ b/src/cli/src/index.ts @@ -18,6 +18,7 @@ import { createLoginCommand, createLogoutCommand } from './commands/auth.js'; import { ApiClient } from './api-client.js'; import { loadConfig } from './config/index.js'; import { loadCredentials } from './auth/index.js'; +import { resolveNameOrId } from './commands/shared.js'; export function createProgram(): Command { const program = new Command() @@ -48,15 +49,27 @@ export function createProgram(): Command { const client = new ApiClient({ baseUrl, token: creds?.token ?? undefined }); - const fetchResource = async (resource: string, id?: string): Promise => { - if (id) { + const fetchResource = async (resource: string, nameOrId?: string): Promise => { + if (nameOrId) { + let id: string; + try { + id = await resolveNameOrId(client, resource, nameOrId); + } catch { + id = nameOrId; + } const item = await client.get(`/api/v1/${resource}/${id}`); return [item]; } return client.get(`/api/v1/${resource}`); }; - const fetchSingleResource = async (resource: string, id: string): Promise => { + const fetchSingleResource = async (resource: string, nameOrId: string): Promise => { + let id: string; + try { + id = await resolveNameOrId(client, resource, nameOrId); + } catch { + id = nameOrId; + } return client.get(`/api/v1/${resource}/${id}`); };