UNPKG

@oada/cli

Version:

CLI OADA client

54 lines 1.79 kB
import { Flags } from '@oclif/core'; import Command from '../../BaseCommand.js'; import getConn from '../../connections.js'; import { shell } from '../../highlight.js'; const examples = [ shell `$ oada ln /resources/my-thingy /bookmarks/thingy`, shell `$ oada ln /resources/thingy1 /resources/thingy2 /bookmarks/thingies/`, ]; class Link extends Command { async run() { const { argv: paths, flags: { force, versioned }, } = await this.parse(Link); const conn = getConn(this.iconfig); const path = paths.pop(); const method = path.endsWith('/') || paths.length > 1 ? 'post' : 'put'; for (const file of paths) { try { const { data: _id } = await conn.get({ path: `${file}/_id`, }); if (typeof _id !== 'string') { throw new TypeError(`${file} is not a valid OADA resource`); } if (force && method === 'put') { await conn.delete({ path: `${file}` }); } await conn[method]({ path, data: versioned ? { _id } : { _id, _rev: 0 }, }); } catch (error) { console.error(error); } } } } Link.description = 'perform an "OADA link"'; Link.aliases = ['ln']; Link.examples = examples; Link.flags = { versioned: Flags.boolean({ char: 'r', default: false, description: 'make versioned link(s)', }), force: Flags.boolean({ char: 'f', default: false, description: 'delete conflicting existing data/links', }), }; Link.strict = false; export default Link; //# sourceMappingURL=link.js.map