mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-07-04 09:01:00 -05:00
Add an option to output JSON
This commit is contained in:
parent
5aba992899
commit
1b71e8b8fe
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ export function builder(yargs: Argv<ParentArguments>) {
|
|||
}
|
||||
|
||||
if (!table.length) {
|
||||
console.log('No Nintendo Accounts');
|
||||
console.warn('No Nintendo Accounts');
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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 ?
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user