feat: add get and describe commands with API client
kubectl-style get (table/json/yaml) and describe commands for servers, profiles, projects, instances. ApiClient for daemon communication. 118 CLI tests passing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,10 @@ import { Command } from 'commander';
|
||||
import { APP_NAME, APP_VERSION } from '@mcpctl/shared';
|
||||
import { createConfigCommand } from './commands/config.js';
|
||||
import { createStatusCommand } from './commands/status.js';
|
||||
import { createGetCommand } from './commands/get.js';
|
||||
import { createDescribeCommand } from './commands/describe.js';
|
||||
import { ApiClient } from './api-client.js';
|
||||
import { loadConfig } from './config/index.js';
|
||||
|
||||
export function createProgram(): Command {
|
||||
const program = new Command()
|
||||
@@ -15,6 +19,33 @@ export function createProgram(): Command {
|
||||
program.addCommand(createConfigCommand());
|
||||
program.addCommand(createStatusCommand());
|
||||
|
||||
// Create API-backed commands
|
||||
const config = loadConfig();
|
||||
const daemonUrl = program.opts().daemonUrl ?? config.daemonUrl;
|
||||
const client = new ApiClient({ baseUrl: daemonUrl });
|
||||
|
||||
const fetchResource = async (resource: string, id?: string): Promise<unknown[]> => {
|
||||
if (id) {
|
||||
const item = await client.get(`/api/v1/${resource}/${id}`);
|
||||
return [item];
|
||||
}
|
||||
return client.get<unknown[]>(`/api/v1/${resource}`);
|
||||
};
|
||||
|
||||
const fetchSingleResource = async (resource: string, id: string): Promise<unknown> => {
|
||||
return client.get(`/api/v1/${resource}/${id}`);
|
||||
};
|
||||
|
||||
program.addCommand(createGetCommand({
|
||||
fetchResource,
|
||||
log: (...args) => console.log(...args),
|
||||
}));
|
||||
|
||||
program.addCommand(createDescribeCommand({
|
||||
fetchResource: fetchSingleResource,
|
||||
log: (...args) => console.log(...args),
|
||||
}));
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user