feat: add json logging to rest of CLI

This commit is contained in:
mrjvs 2025-09-19 22:47:18 +02:00
parent 25b871e3b5
commit 6b95420e0f
2 changed files with 37 additions and 27 deletions

View File

@ -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<void> => {
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('<id>', 'BOSS app ID to lookup')
.action(async (id: string) => {
.action(commandHandler<[string]>(async (cmd): Promise<void> => {
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')

View File

@ -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('<app_id>', 'BOSS app to search in')
.action(async (appId: string) => {
.action(commandHandler<[string]>(async (cmd): Promise<void> => {
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('<app_id>', 'BOSS app ID that contains the task')
.argument('<id>', 'Task ID to lookup')
.action(async (appId: string, taskId: string) => {
.action(commandHandler<[string, string]>(async (cmd): Promise<void> => {
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>', 'Id of the task')
.requiredOption('--title-id <titleId>', '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<void> => {
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('<app_id>', 'BOSS app ID that contains the task')
.argument('<id>', 'Task ID to delete')
.action(async (appId: string, taskId: string) => {
.action(commandHandler<[string, string]>(async (cmd): Promise<void> => {
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')