UNPKG

@decentralized-identity/ion-cli

Version:

A Command Line Interface (CLI) to make working with the ION network and using ION DIDs easy peasy lemon squeezy.

43 lines (42 loc) 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = require("@oclif/command"); const fs = require("fs-extra"); const path = require("path"); const CacheItem_1 = require("../../CacheItem"); const { cli } = require('cli-ux'); class List extends command_1.Command { async run() { const { flags } = this.parse(List); // Clear the cache const cacheDirectory = path.join(flags.directory, 'cache'); const cachedFiles = await fs.readdir(cacheDirectory); const cacheList = await Promise.all(cachedFiles.map(async (file) => { const cachedItem = await CacheItem_1.default.read(flags.directory, file); if (cachedItem) { return { name: cachedItem['name'], did: cachedItem.did, lastResolved: cachedItem.lastResolved, published: cachedItem.published }; } })); // Output as a table cli.table(cacheList, { name: {}, lastResolved: {}, published: {}, did: {} }, Object.assign({ printLine: this.log }, flags)); this.exit(); } } exports.default = List; List.description = 'Lists the cached DIDs.'; List.examples = [ '$ ion cache:list -d d:\dids', ]; List.flags = Object.assign({ help: command_1.flags.help({ char: 'h' }), // Flag for specifying a directory to which keys and documents should be saved. directory: command_1.flags.string({ char: 'd', description: 'that contains the cache. Defaults to environment variable DID_PATH if set.', env: 'DID_PATH', required: true }) }, cli.table.flags());