@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.
52 lines (51 loc) • 2.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = require("@oclif/command");
const Output_1 = require("../Output");
const StorageItem_1 = require("../StorageItem");
const { cli } = require('cli-ux');
class Load extends command_1.Command {
async run() {
const { args, flags } = this.parse(Load);
// Load the DID and return
cli.action.start(`Loading DID '${args.name}' from '${flags.directory}'.`);
const didPackage = await StorageItem_1.default.load(flags.directory, args.name);
cli.action.stop();
let packageSubset;
switch (flags.what) {
case 'InitialState':
packageSubset = didPackage.initialState;
break;
case 'Keys':
packageSubset = didPackage.keys;
break;
default:
packageSubset = didPackage;
}
this.log(Output_1.default.toJson(packageSubset, flags.escape));
this.exit();
}
}
exports.default = Load;
Load.description = 'Loads a DID from the directory using the friendly name.';
Load.examples = [
'$ ion load FriendlyName',
'$ ion load FriendlyName -d d:/dids',
'$ ion load FriendlyName -d d:/dids --escape',
];
Load.flags = {
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: 'to which the DID should be saved. Defaults to environment variable DID_PATH if set.', env: 'DID_PATH', required: true }),
// Flag for specifying what specific objects to load from the package
what: command_1.flags.enum({ description: 'specify the objects from the specified package to load.', options: ['All', 'InitialState', 'Keys'], default: 'All' }),
// Flag for specifying the JSON string output should be escaped.
escape: command_1.flags.boolean({ description: 'specifies that the output JSON string should be escaped. Use this when using the output as input to another command.' }),
};
Load.args = [
{
name: 'name',
required: true,
description: 'name for the new DID. Name should not include spaces or special characters.',
},
];