From d7e641d60443266724b53163ef3c6fecbfbabfae Mon Sep 17 00:00:00 2001 From: mrjvs Date: Thu, 4 Sep 2025 01:04:24 +0200 Subject: [PATCH] feat: add task management to the CLI --- src/cli/tasks.cmd.ts | 64 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/src/cli/tasks.cmd.ts b/src/cli/tasks.cmd.ts index 9b18fed..07ec73e 100644 --- a/src/cli/tasks.cmd.ts +++ b/src/cli/tasks.cmd.ts @@ -1,37 +1,81 @@ import { Command } from 'commander'; +import { getCliContext } from './utils'; const listCmd = new Command('ls') .description('List all tasks in BOSS') .argument('', 'BOSS app to search in') - .action(async () => { - console.log('Test'); + .action(async (appId: string) => { + const ctx = getCliContext(); + const { tasks } = await ctx.grpc.listTasks({}); + const filteredTasks = tasks.filter(v => v.bossAppId === appId); + console.table(filteredTasks.map(v => ({ + 'Task ID': v.id, + 'Description': v.description, + 'Status': v.status + }))); }); const viewCmd = new Command('view') .description('Look up a specific task') .argument('', 'BOSS app ID that contains the task') .argument('', 'Task ID to lookup') - .action(async () => { - console.log('Test'); + .action(async (appId: string, taskId: string) => { + const ctx = getCliContext(); + const { tasks } = await ctx.grpc.listTasks({}); + const task = tasks.find(v => v.bossAppId === appId && v.id === taskId); + if (!task) { + console.log(`Could not find task with ID ${taskId} in app ${appId}`); + return; + } + console.log({ + taskId: task.id, + inGameId: task.inGameId, + description: task.description, + titleId: task.titleId, + bossAppId: task.bossAppId, + creatorPid: task.creatorPid, + status: task.status, + createdAt: new Date(Number(task.createdTimestamp)), + updatedAt: new Date(Number(task.updatedTimestamp)) + }); }); const createCmd = new Command('create') .description('Create a new task') .argument('', 'BOSS app to store the task in') - .action(async () => { - console.log('Test'); + .requiredOption('--id ', 'Id of the task') + .requiredOption('--title-id ', 'Title ID for the task') + .requiredOption('--country ', 'Description of the task') + .option('--desc [desc]', 'Description of the task') + .action(async (appId: string, opts: { id: string; titleId: string; desc?: string; country: string }) => { + const ctx = getCliContext(); + const { task } = await ctx.grpc.registerTask({ + bossAppId: appId, + id: opts.id, + titleId: opts.titleId, + description: opts.desc ?? '', + country: opts.country + }); + if (!task) { + console.log(`Failed to create task!`); + return; + } + console.log(`Created task with ID ${task.id}`); }); const deleteCmd = new Command('delete') .description('Delete a task') .argument('', 'BOSS app ID that contains the task') .argument('', 'Task ID to delete') - .action(async () => { - console.log('Test'); + .action(async (appId: string, taskId: string) => { + const ctx = getCliContext(); + await ctx.grpc.deleteTask({ + bossAppId: appId, + id: taskId + }); + console.log(`Deleted task with ID ${taskId}`); }); -// TODO add updateCmd - export const taskCmd = new Command('task') .description('Manage all the tasks in BOSS') .addCommand(listCmd)