dwnpm
Version:
Decentralized Registry Package Manager (DRPM) helps developers publish, install, find and manage Decentralized Packages (DPKs) published to Decentralized Web Nodes (DWNs). DRPM does this by looking up a Decentralized Identifier (DID) to find its DID docum
41 lines (40 loc) • 1.43 kB
text/typescript
import { Profile } from '../../lib/profile.js';
import { Logger } from '../../utils/logger.js';
import { ICommand } from '../drpm.js';
import { DRegistryPackageManagerError } from './error.js';
export class ContextCommand implements ICommand {
async execute({ options, subcommand }: { options?: any; subcommand?: string}): Promise<void> {
try {
const name = options?.name ?? Profile.loadStaticSync().name;
const profile = new Profile(name);
switch (subcommand) {
case 'create':
await profile.context.create(options);
await profile.save();
break;
case 'read':
profile.context.read(options);
break;
case 'update':
profile.context.update(options);
profile.context.save({ name: profile.context.name, context: profile.context.data });
break;
case 'delete':
profile.context.delete(options);
profile.context.save({ name: profile.context.name, context: profile.context.data });
break;
case 'backup':
profile.context.backup(options);
break;
case 'recover':
profile.context.recover(options);
break;
default:
throw new DRegistryPackageManagerError(`ContextCommand: Unknown action ${subcommand}`);
}
} catch (error: any) {
Logger.error(error.message);
throw error;
}
}
}