diff --git a/packages/cli/src/commands/list.js b/packages/cli/src/commands/list.js index 111b601455..4305879cdd 100644 --- a/packages/cli/src/commands/list.js +++ b/packages/cli/src/commands/list.js @@ -1,15 +1,34 @@ /* global process */ import os from 'os'; import { E } from '@endo/far'; +import { makeRefIterator } from '@endo/daemon'; import { withEndoHost } from '../context.js'; -export const list = async ({ directoryPath }) => +export const list = async ({ directoryPath, follow, json }) => withEndoHost({ os, process }, async ({ host: party }) => { if (directoryPath !== undefined) { party = E(party).lookup(...directoryPath.split('.')); } - const petNames = await E(party).list(); - for await (const petName of petNames) { - console.log(petName); + if (follow) { + const topic = await E(party).followNames(); + const iterator = makeRefIterator(topic); + if (json) { + for await (const change of iterator) { + console.log(JSON.stringify(change)); + } + } else { + for await (const change of iterator) { + if (change.add !== undefined) { + console.log(`+${change.add}`); + } else if (change.remove !== undefined) { + console.log(`-${change.remove}`); + } + } + } + } else { + const petNames = await E(party).list(); + for await (const petName of petNames) { + console.log(petName); + } } }); diff --git a/packages/cli/src/endo.js b/packages/cli/src/endo.js index 8495ad2c20..c736613104 100644 --- a/packages/cli/src/endo.js +++ b/packages/cli/src/endo.js @@ -256,9 +256,12 @@ export const main = async rawArgs => { program .command('list [directory]') .description('show names known to the current or specified directory') + .option('-f,--follow', 'Follow updates') + .option('-j,--json', 'JSON format output') .action(async (directoryPath, cmd) => { + const { follow, json } = cmd.opts(); const { list } = await import('./commands/list.js'); - return list({ directoryPath }); + return list({ directoryPath, follow, json }); }); program