Skip to content

Commit

Permalink
feat(cli): add choices when selecting credential Subject in CLI (#898)
Browse files Browse the repository at this point in the history
* Add choices when selecting credential Subject in CLI

* Change from list input type to autocomplete

* Remove validation when choosing subject DID
  • Loading branch information
tientaidev authored May 27, 2022
1 parent b96ded6 commit c47c08e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/cli/src/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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',
Expand Down

0 comments on commit c47c08e

Please sign in to comment.