-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
cmd/list.js
and sidecar/ops/list.js
- Loading branch information
1 parent
0225e72
commit e36dee1
Showing
5 changed files
with
45 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
'use strict' | ||
const { outputter } = require('./iface') | ||
|
||
const listBundle = () => { | ||
console.log('List bundle') | ||
const bundles = (items) => { | ||
let out = 'BUNDLES\n' | ||
for (const b of items) { | ||
out += `- link: ${b.link}\n` | ||
out += ` appStorage: ${b.appStorage}\n` | ||
out += ` encryptionKey: ${b.encryptionKey}\n` | ||
out += ` tags: ${b.tags}\n` | ||
} | ||
return out | ||
} | ||
|
||
const listAll = () => { | ||
listBundle() | ||
} | ||
const all = (items) => bundles(items) | ||
|
||
const output = outputter('list', { | ||
bundle: listBundle, | ||
all: listAll | ||
bundles, | ||
all, | ||
error: (err) => `List Error (code: ${err.code || 'none'}) ${err.stack}`, | ||
final: () => false | ||
}) | ||
|
||
module.exports = (ipc) => async function list (cmd) { | ||
if (cmd.flags.bundle) { | ||
await output(false, [{ tag: 'bundle' }]) | ||
} else { | ||
await output(false, [{ tag: 'all' }]) | ||
const data = await ipc.list({ bundles: cmd.flags.bundles }) | ||
if (cmd.flags.bundles) { | ||
return await output(false, data, { tag: 'bundles' }, ipc) | ||
} | ||
return await output(false, data, { tag: 'all' }, ipc) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict' | ||
const Opstream = require('../lib/opstream') | ||
|
||
module.exports = class List extends Opstream { | ||
constructor (...args) { | ||
super((...args) => this.#op(...args), ...args) | ||
} | ||
|
||
async #op ({ bundles }) { | ||
const all = await this.model.allBundles() | ||
this.push({ | ||
tag: bundles ? 'bundles' : 'all', | ||
data: all.map(b => ({ | ||
link: b.link, | ||
appStorage: b.appStorage, | ||
encryptionKey: b.encryptionKey, | ||
tags: b.tags | ||
})) | ||
}) | ||
} | ||
} |