From c47c08e2ce9ef676cc429bcaf063bbe8e38a352c Mon Sep 17 00:00:00 2001 From: Tyler <43933775+tientaidev@users.noreply.github.com> Date: Sat, 28 May 2022 02:26:51 +0700 Subject: [PATCH] feat(cli): add choices when selecting credential Subject in CLI (#898) * Add choices when selecting credential Subject in CLI * Change from list input type to autocomplete * Remove validation when choosing subject DID --- packages/cli/src/credential.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/credential.ts b/packages/cli/src/credential.ts index c6dcfefa7..9438be61b 100644 --- a/packages/cli/src/credential.ts +++ b/packages/cli/src/credential.ts @@ -7,6 +7,8 @@ import * as json5 from 'json5' import { readStdin } from './util' import { CredentialPayload } from '@veramo/core' +const fuzzy = require('fuzzy') + const credential = program.command('credential').description('W3C Verifiable Credential') credential @@ -18,6 +20,10 @@ credential .action(async (cmd) => { const agent = getAgent(program.opts().config) const identifiers = await agent.didManagerFind() + + const knownDids = await agent.dataStoreORMGetIdentifiers() + const subjects = [...knownDids.map((id) => id.did)] + if (identifiers.length === 0) { console.error('No dids') process.exit() @@ -39,10 +45,16 @@ credential message: 'Issuer DID', }, { - type: 'input', + type: 'autocomplete', name: 'sub', + pageSize: 15, + source: async (answers: any, input: string) => { + const res = fuzzy + .filter(input, subjects) + .map((el: any) => (typeof el === 'string' ? el : el.original)) + return res + }, message: 'Subject DID', - default: identifiers[0].did, }, { type: 'input',