From f88c087f29e1e3f493b628bc941994700db88f68 Mon Sep 17 00:00:00 2001 From: Filipi Zimermann Date: Sun, 3 Apr 2022 22:57:45 -0300 Subject: [PATCH] Add JSON format option to find command --- app/views/resources/index.js | 4 +++- passbolt-find.js | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/resources/index.js b/app/views/resources/index.js index f23385f..6cb70ea 100644 --- a/app/views/resources/index.js +++ b/app/views/resources/index.js @@ -43,9 +43,11 @@ class ResourceIndexView extends AppView { } } - render() { + render(format = null) { if (this.data.length === 0) { console.log('No resources to display. Create one first!'); + } else if (format == 'json') { + console.log(JSON.stringify(this.data)); } else { console.log(this.columnify(this.data, { minWidth: 20, diff --git a/passbolt-find.js b/passbolt-find.js index 2763b33..9b06917 100755 --- a/passbolt-find.js +++ b/passbolt-find.js @@ -25,6 +25,7 @@ const {list} = require('./app/lib/coercion'); .option('-u, --fingerprint ', 'The user key fingerprint to authenticate with') .option('-p, --passphrase ', 'The key passphrase') .option('--columns ', 'Coma separated columns to display', list) + .option('--json', 'Output resources in JSON format') .option('-v, --verbose', 'Display additional debug information') .parse(process.argv); @@ -33,7 +34,7 @@ const {list} = require('./app/lib/coercion'); try { let data = await resourceController.index(); const view = new ResourceIndexView(data, program.opts().columns); - view.render(); + view.render(program.opts().json ? 'json' : null); } catch (err) { resourceController.error(err); }