Add an option to output JSON

This commit is contained in:
Samuel Elliott 2022-03-16 20:16:53 +00:00
parent 5aba992899
commit 1b71e8b8fe
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
8 changed files with 74 additions and 8 deletions

View File

@ -16,13 +16,19 @@ export function builder(yargs: Argv<ParentArguments>) {
}).option('token', {
describe: 'Nintendo Account session token',
type: 'string',
}).option('json', {
describe: 'Output raw JSON',
type: 'boolean',
}).option('json-pretty-print', {
describe: 'Output pretty-printed JSON',
type: 'boolean',
});
}
type Arguments = YargsArguments<ReturnType<typeof builder>>;
export async function handler(argv: ArgumentsCamelCase<Arguments>) {
console.log('Listing announcements');
console.warn('Listing announcements');
const storage = await initStorage(argv.dataPath);
@ -37,6 +43,15 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
const webservices = await nso.getWebServices();
const activeevent = await nso.getActiveEvent();
if (argv.jsonPrettyPrint) {
console.log(JSON.stringify(announcements.result, null, 4));
return;
}
if (argv.json) {
console.log(JSON.stringify(announcements.result));
return;
}
const table = new Table({
head: [
'ID',

View File

@ -17,13 +17,19 @@ export function builder(yargs: Argv<ParentArguments>) {
}).option('token', {
describe: 'Nintendo Account session token',
type: 'string',
}).option('json', {
describe: 'Output raw JSON',
type: 'boolean',
}).option('json-pretty-print', {
describe: 'Output pretty-printed JSON',
type: 'boolean',
});
}
type Arguments = YargsArguments<ReturnType<typeof builder>>;
export async function handler(argv: ArgumentsCamelCase<Arguments>) {
console.log('Listing friends');
console.warn('Listing friends');
const storage = await initStorage(argv.dataPath);
@ -38,6 +44,15 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
const webservices = await nso.getWebServices();
const activeevent = await nso.getActiveEvent();
if (argv.jsonPrettyPrint) {
console.log(JSON.stringify(friends.result.friends, null, 4));
return;
}
if (argv.json) {
console.log(JSON.stringify(friends.result.friends));
return;
}
const table = new Table({
head: [
'ID',

View File

@ -52,7 +52,7 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
const i = new ZncNotifications(argv, storage, token, nso, data);
console.log('Authenticated as Nintendo Account %s (NA %s, NSO %s)',
console.warn('Authenticated as Nintendo Account %s (NA %s, NSO %s)',
data.user.screenName, data.user.nickname, data.nsoAccount.user.name);
await i.init();

View File

@ -59,7 +59,7 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
const i = new ZncProxyDiscordPresence(argv, argv.presenceUrl);
console.log('Not authenticated; using znc proxy');
console.warn('Not authenticated; using znc proxy');
await i.init();
@ -80,7 +80,7 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
const i = new ZncDiscordPresence(argv, storage, token, nso, data);
console.log('Authenticated as Nintendo Account %s (NA %s, NSO %s)',
console.warn('Authenticated as Nintendo Account %s (NA %s, NSO %s)',
data.user.screenName, data.user.nickname, data.nsoAccount.user.name);
await i.init();

View File

@ -44,7 +44,7 @@ export function builder(yargs: Argv<ParentArguments>) {
}
if (!table.length) {
console.log('No Nintendo Accounts');
console.warn('No Nintendo Accounts');
return;
}

View File

@ -16,13 +16,19 @@ export function builder(yargs: Argv<ParentArguments>) {
}).option('token', {
describe: 'Nintendo Account session token',
type: 'string',
}).option('json', {
describe: 'Output raw JSON',
type: 'boolean',
}).option('json-pretty-print', {
describe: 'Output pretty-printed JSON',
type: 'boolean',
});
}
type Arguments = YargsArguments<ReturnType<typeof builder>>;
export async function handler(argv: ArgumentsCamelCase<Arguments>) {
console.log('Listing web services');
console.warn('Listing web services');
const storage = await initStorage(argv.dataPath);
@ -37,6 +43,15 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
const webservices = await nso.getWebServices();
const activeevent = await nso.getActiveEvent();
if (argv.jsonPrettyPrint) {
console.log(JSON.stringify(webservices.result, null, 4));
return;
}
if (argv.json) {
console.log(JSON.stringify(webservices.result));
return;
}
const table = new Table({
head: [
'ID',

View File

@ -19,6 +19,12 @@ export function builder(yargs: Argv<ParentArguments>) {
}).option('token', {
describe: 'Nintendo Account session token',
type: 'string',
}).option('json', {
describe: 'Output raw JSON',
type: 'boolean',
}).option('json-pretty-print', {
describe: 'Output pretty-printed JSON',
type: 'boolean',
});
}
@ -54,6 +60,21 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
na_lang: data.user.language,
}).toString();
if (argv.jsonPrettyPrint) {
console.log(JSON.stringify({
webservice,
token: webserviceToken.result,
}, null, 4));
return;
}
if (argv.json) {
console.log(JSON.stringify({
webservice,
token: webserviceToken.result,
}));
return;
}
console.log('Web service', {
name: webservice.name,
url: url.toString(),

View File

@ -50,7 +50,7 @@ export async function getToken(storage: persist.LocalStorage, token: string, pro
const existingToken: SavedToken | undefined = await storage.getItem('NsoToken.' + token);
if (!existingToken || existingToken.expires_at <= Date.now()) {
console.log('Authenticating to Nintendo Switch Online app');
console.warn('Authenticating to Nintendo Switch Online app');
debug('Authenticating to znc with session token');
const {nso, data} = proxy_url ?