diff --git a/src/cli/apps.cmd.ts b/src/cli/apps.cmd.ts index 62a0289..59f3b16 100644 --- a/src/cli/apps.cmd.ts +++ b/src/cli/apps.cmd.ts @@ -1,23 +1,27 @@ import { Command } from 'commander'; -import { getCliContext, prettyTrunc } from './utils'; +import { commandHandler, getCliContext, prettyTrunc } from './utils'; +import { logOutputList, logOutputObject } from './output'; const listCmd = new Command('ls') .description('List all apps in BOSS') - .action(async () => { + .action(commandHandler<[]>(async (cmd): Promise => { const ctx = getCliContext(); const { apps } = await ctx.grpc.listKnownBOSSApps({}); - console.table(apps.map(v => ({ - 'App ID': v.bossAppId, - 'Name': prettyTrunc(v.name, 20), - 'Title ID': v.titleId, - 'Title region': v.titleRegion - }))); - }); + logOutputList(cmd.format, apps.map(v => ({ + name: prettyTrunc(v.name, 20) + })), { + bossAppId: 'App ID', + name: 'Name', + titleId: 'Title ID', + titleRegion: 'Title region' + }); + })); const viewCmd = new Command('view') .description('Look up a specific BOSS app') .argument('', 'BOSS app ID to lookup') - .action(async (id: string) => { + .action(commandHandler<[string]>(async (cmd): Promise => { + const [id] = cmd.args; const ctx = getCliContext(); const { apps } = await ctx.grpc.listKnownBOSSApps({}); const app = apps.find(v => v.bossAppId === id); @@ -26,14 +30,14 @@ const viewCmd = new Command('view') return; } - console.log({ + logOutputObject(cmd.format, { appId: app.bossAppId, name: app.name, titleId: app.titleId, titleRegion: app.titleRegion, knownTasks: app.tasks }); - }); + })); export const appCmd = new Command('app') .description('Manage all the apps in BOSS') diff --git a/src/cli/tasks.cmd.ts b/src/cli/tasks.cmd.ts index bc70229..432344d 100644 --- a/src/cli/tasks.cmd.ts +++ b/src/cli/tasks.cmd.ts @@ -1,25 +1,28 @@ import { Command } from 'commander'; -import { getCliContext } from './utils'; +import { commandHandler, getCliContext } from './utils'; +import { logOutputList, logOutputObject } from './output'; const listCmd = new Command('ls') .description('List all tasks in BOSS') .argument('', 'BOSS app to search in') - .action(async (appId: string) => { + .action(commandHandler<[string]>(async (cmd): Promise => { + const [appId] = cmd.args; 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 - }))); - }); + logOutputList(cmd.format, filteredTasks, { + id: 'Task ID', + description: 'Description', + status: '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 (appId: string, taskId: string) => { + .action(commandHandler<[string, string]>(async (cmd): Promise => { + const [appId, taskId] = cmd.args; const ctx = getCliContext(); const { tasks } = await ctx.grpc.listTasks({}); const task = tasks.find(v => v.bossAppId === appId && v.id === taskId); @@ -27,7 +30,7 @@ const viewCmd = new Command('view') console.log(`Could not find task with ID ${taskId} in app ${appId}`); return; } - console.log({ + logOutputObject(cmd.format, { taskId: task.id, inGameId: task.inGameId, description: task.description, @@ -38,7 +41,7 @@ const viewCmd = new Command('view') createdAt: new Date(Number(task.createdTimestamp)), updatedAt: new Date(Number(task.updatedTimestamp)) }); - }); + })); const createCmd = new Command('create') .description('Create a new task') @@ -46,8 +49,10 @@ const createCmd = new Command('create') .requiredOption('--id ', 'Id of the task') .requiredOption('--title-id ', 'Title ID for the task') .option('--desc [desc]', 'Description of the task') - .action(async (appId: string, opts: { id: string; titleId: string; desc?: string }) => { + .action(commandHandler<[string]>(async (cmd): Promise => { + const [appId] = cmd.args; const ctx = getCliContext(); + const opts = cmd.opts<{ id: string; titleId: string; desc?: string }>(); const { task } = await ctx.grpc.registerTask({ bossAppId: appId, id: opts.id, @@ -60,20 +65,21 @@ const createCmd = new Command('create') 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 (appId: string, taskId: string) => { + .action(commandHandler<[string, string]>(async (cmd): Promise => { + const [appId, taskId] = cmd.args; const ctx = getCliContext(); await ctx.grpc.deleteTask({ bossAppId: appId, id: taskId }); console.log(`Deleted task with ID ${taskId}`); - }); + })); export const taskCmd = new Command('task') .description('Manage all the tasks in BOSS')