diff --git a/crunchy.ts b/crunchy.ts index 24a4457..63983a6 100644 --- a/crunchy.ts +++ b/crunchy.ts @@ -113,7 +113,7 @@ export default class Crunchy implements ServiceClass { } else if(argv.new){ await this.refreshToken(); - await this.getNewlyAdded(argv.page, argv.raw); + await this.getNewlyAdded(argv.page, argv.raw, argv.rawoutput); } else if(argv.search && argv.search.length > 2){ await this.refreshToken(); @@ -1028,7 +1028,7 @@ export default class Crunchy implements ServiceClass { } } - public async getNewlyAdded(page?: number, raw: boolean = false) { + public async getNewlyAdded(page?: number, raw: boolean = false, rawoutput?: string) { if(!this.token.access_token){ console.error('Authentication required!'); return; @@ -1054,6 +1054,14 @@ export default class Crunchy implements ServiceClass { if (raw) { console.info(JSON.stringify(newlyAddedResults, null, 2)); + if (rawoutput) { + try { + fs.writeFileSync(rawoutput, JSON.stringify(newlyAddedResults), { encoding: 'utf-8' }); + console.info(`Raw output saved to ${rawoutput}`); + } catch (e) { + console.error(`Failed to save raw output to ${rawoutput}:`, e); + } + } return; } diff --git a/modules/module.app-args.ts b/modules/module.app-args.ts index 65bd7f4..5697445 100644 --- a/modules/module.app-args.ts +++ b/modules/module.app-args.ts @@ -71,6 +71,7 @@ let argvC: { nosess: string; debug: boolean | undefined; raw: boolean; + rawoutput: string; nocleanup: boolean; help: boolean | undefined; service: 'crunchy' | 'hidive' | 'ao' | 'adn'; diff --git a/modules/module.args.ts b/modules/module.args.ts index 3b843f4..81ed8e7 100644 --- a/modules/module.args.ts +++ b/modules/module.args.ts @@ -843,6 +843,18 @@ const args: TAppArg[] = [ default: false } }, + { + name: 'rawoutput', + describe: 'Provide a path to output the raw data from the API into a file (Where applicable, the feature is a WIP)', + docDescribe: true, + group: 'util', + service: ['all'], + type: 'string', + usage: '', + default: { + default: '' + } + }, { name: 'force', describe: 'Set the default option for the \'alredy exists\' prompt',