mirror of
https://github.com/PretendoNetwork/BOSS.git
synced 2026-04-24 23:17:47 -05:00
feat: implement boss apps into CLI
This commit is contained in:
parent
616a24d8d7
commit
f8d5a0c7e3
|
|
@ -1,19 +1,38 @@
|
|||
import { Command } from 'commander';
|
||||
import { getCliContext } from './utils';
|
||||
import { getCliContext, prettyTrunc } from './utils';
|
||||
|
||||
const listCmd = new Command('ls')
|
||||
.description('List all apps in BOSS')
|
||||
.action(async () => {
|
||||
const ctx = getCliContext();
|
||||
const apps = await ctx.grpc.listKnownBOSSApps({});
|
||||
console.log(apps);
|
||||
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
|
||||
})));
|
||||
});
|
||||
|
||||
const viewCmd = new Command('view')
|
||||
.description('Look up a specific BOSS app')
|
||||
.argument('<id>', 'BOSS app ID to lookup')
|
||||
.action(async () => {
|
||||
console.log('Test');
|
||||
.action(async (id: string) => {
|
||||
const ctx = getCliContext();
|
||||
const { apps } = await ctx.grpc.listKnownBOSSApps({});
|
||||
const app = apps.find(v => v.bossAppId === id);
|
||||
if (!app) {
|
||||
console.log(`Could not find BOSS app with ID ${id}`);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log({
|
||||
appId: app.bossAppId,
|
||||
name: app.name,
|
||||
titleId: app.titleId,
|
||||
titleRegion: app.titleRegion,
|
||||
knownTasks: app.tasks
|
||||
});
|
||||
});
|
||||
|
||||
export const appCmd = new Command('app')
|
||||
|
|
|
|||
|
|
@ -10,4 +10,8 @@ const program = baseProgram
|
|||
.addCommand(taskCmd)
|
||||
.addCommand(fileCmd);
|
||||
|
||||
program.parseAsync(process.argv).catch(console.error);
|
||||
program.parseAsync(process.argv)
|
||||
.catch(console.error)
|
||||
.then(() => {
|
||||
process.exit(0); // forcibly close as GRPC channels keep process going
|
||||
});
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ export function getCliContext(): CliContext {
|
|||
throw new Error('Missing env variable PN_BOSS_CLI_GRPC_APIKEY');
|
||||
}
|
||||
|
||||
console.log(`Connecting to BOSS server at ${grpcHost}`);
|
||||
|
||||
const channel = createChannel(grpcHost);
|
||||
const client: BOSSClient = createClient(BOSSDefinition, channel, {
|
||||
'*': {
|
||||
|
|
@ -32,3 +30,10 @@ export function getCliContext(): CliContext {
|
|||
grpc: client
|
||||
};
|
||||
}
|
||||
|
||||
export function prettyTrunc(str: string, len: number): string {
|
||||
if (str.length > len) {
|
||||
return `${str.slice(0, len)}...`;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user