-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): Follow list changes (merge #2105)
- Loading branch information
Showing
2 changed files
with
27 additions
and
5 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
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); | ||
} | ||
} | ||
}); |
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