UNPKG

@oada/cli

Version:

CLI OADA client

44 lines 1.58 kB
import { setInterval } from 'node:timers/promises'; import { Args, Flags } from '@oclif/core'; import { oadaify } from '@oada/oadaify'; import Command from '../BaseCommand.js'; import { loadFile, output } from '../io.js'; import getConn from '../connections.js'; const examples = ['']; class Poll extends Command { async run() { const { args: { path: rawpath }, flags: { out, tree: treefile, interval }, } = await this.parse(Poll); const conn = getConn(this.iconfig); const tree = treefile ? (await loadFile(treefile)) : undefined; const path = `${rawpath}`; await output(out, async function* () { const poll = setInterval(interval); for await (const _ of poll) { const { data } = await conn.get({ path, tree }); if (Buffer.isBuffer(data)) { yield data; return; } const oadaified = oadaify(data); yield oadaified; } }, this.iconfig); } } Poll.description = 'Poll an OADA path with periodic GETs'; Poll.aliases = ['POLL']; Poll.examples = examples; Poll.flags = { out: Flags.string({ char: 'o', default: '-' }), tree: Flags.string({ char: 'T', description: 'file containing an OADA tree to use for a tree GET', }), interval: Flags.integer({ char: 'i', default: 1000 }), }; Poll.args = { path: Args.string({ required: true, description: 'OADA path to poll' }), }; Poll.strict = true; export default Poll; //# sourceMappingURL=poll.js.map