feat(cli): add initiative commands (create, list, get)
Add CLI commands for initiative management: - cw initiative create <name> - create with optional description - cw initiative list - list all with optional status filter - cw initiative get <id> - get details by ID
This commit is contained in:
@@ -642,6 +642,87 @@ export function createCli(serverHandler?: (port?: number) => Promise<void>): Com
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Initiative command group
|
||||||
|
const initiativeCommand = program
|
||||||
|
.command('initiative')
|
||||||
|
.description('Manage initiatives');
|
||||||
|
|
||||||
|
// cw initiative create <name>
|
||||||
|
initiativeCommand
|
||||||
|
.command('create <name>')
|
||||||
|
.description('Create a new initiative')
|
||||||
|
.option('-d, --description <description>', 'Initiative description')
|
||||||
|
.action(async (name: string, options: { description?: string }) => {
|
||||||
|
try {
|
||||||
|
const client = createDefaultTrpcClient();
|
||||||
|
const initiative = await client.createInitiative.mutate({
|
||||||
|
name,
|
||||||
|
description: options.description,
|
||||||
|
});
|
||||||
|
console.log(`Created initiative: ${initiative.id}`);
|
||||||
|
console.log(` Name: ${initiative.name}`);
|
||||||
|
if (initiative.description) {
|
||||||
|
console.log(` Description: ${initiative.description}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to create initiative:', (error as Error).message);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// cw initiative list
|
||||||
|
initiativeCommand
|
||||||
|
.command('list')
|
||||||
|
.description('List all initiatives')
|
||||||
|
.option('-s, --status <status>', 'Filter by status (active, completed, archived)')
|
||||||
|
.action(async (options: { status?: string }) => {
|
||||||
|
// Validate status if provided
|
||||||
|
const validStatuses = ['active', 'completed', 'archived'];
|
||||||
|
if (options.status && !validStatuses.includes(options.status)) {
|
||||||
|
console.error(`Invalid status: ${options.status}`);
|
||||||
|
console.error(`Valid statuses: ${validStatuses.join(', ')}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const client = createDefaultTrpcClient();
|
||||||
|
const initiatives = await client.listInitiatives.query(
|
||||||
|
options.status ? { status: options.status as 'active' | 'completed' | 'archived' } : undefined
|
||||||
|
);
|
||||||
|
if (initiatives.length === 0) {
|
||||||
|
console.log('No initiatives found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const init of initiatives) {
|
||||||
|
console.log(`${init.id} ${init.status.padEnd(10)} ${init.name}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to list initiatives:', (error as Error).message);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// cw initiative get <id>
|
||||||
|
initiativeCommand
|
||||||
|
.command('get <id>')
|
||||||
|
.description('Get initiative details')
|
||||||
|
.action(async (id: string) => {
|
||||||
|
try {
|
||||||
|
const client = createDefaultTrpcClient();
|
||||||
|
const initiative = await client.getInitiative.query({ id });
|
||||||
|
console.log(`ID: ${initiative.id}`);
|
||||||
|
console.log(`Name: ${initiative.name}`);
|
||||||
|
console.log(`Status: ${initiative.status}`);
|
||||||
|
if (initiative.description) {
|
||||||
|
console.log(`Description: ${initiative.description}`);
|
||||||
|
}
|
||||||
|
console.log(`Created: ${new Date(initiative.createdAt).toISOString()}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to get initiative:', (error as Error).message);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return program;
|
return program;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user