UNPKG

ad4m-host

Version:
48 lines (47 loc) 1.89 kB
import { buildAd4mClient, prettify } from './util'; export const command = 'neighbourhood [action]'; export const desc = 'Neighbourhood related action'; export const builder = (yargs) => yargs .positional('action', { type: 'string', describe: 'Action that should be executed on the neighbourhood', choices: ['publishFromPerspective', 'joinFromUrl'], }) .options({ uuid: { type: "string", describe: 'Identifier of the perspective' }, address: { type: "string", describe: 'Address of the link language used for the neighbourhood' }, meta: { type: "string", describe: 'Metadata of the neighbourhood' }, url: { type: "string", describe: 'URL of the neighbourhood' }, }); export const handler = async (argv) => { const { server, uuid, address, meta, url, action } = argv; const ad4mClient = buildAd4mClient(server); switch (action) { case 'publishFromPerspective': await publishFromPerspective(ad4mClient, uuid, address, meta); break; case 'joinFromUrl': await joinFromUrl(ad4mClient, url); break; default: console.info(`Action "${argv.action}" is not defined on neighbourhood.`); break; } process.exit(); }; async function publishFromPerspective(ad4mClient, uuid, address, meta) { if (uuid && address && meta) { const result = await ad4mClient.neighbourhood.publishFromPerspective(uuid, address, JSON.parse(meta)); prettify(result); return; } console.info('Neighbourhood publishFromPerspective action is missiong param <uuid> <address> <meta>'); } async function joinFromUrl(ad4mClient, url) { if (url) { const result = await ad4mClient.neighbourhood.joinFromUrl(url); prettify(result); return; } console.info('Neighbourhood joinFromUrl action is missiong param <url>'); }