Skip to content

Commit

Permalink
feat(cli): Follow list changes (merge #2105)
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal authored Feb 28, 2024
2 parents c5d012f + c5eb0f1 commit 1ab1198
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
27 changes: 23 additions & 4 deletions packages/cli/src/commands/list.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
});
5 changes: 4 additions & 1 deletion packages/cli/src/endo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1ab1198

Please sign in to comment.