From 19ca8af273dbd07285d2fbe83a447ff7eaceaa7e Mon Sep 17 00:00:00 2001 From: Angelito Salud Date: Tue, 11 Feb 2020 19:50:04 +0800 Subject: [PATCH] Added a checker if optionality required in addition to map type --- src/step-aware-command.ts | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/step-aware-command.ts b/src/step-aware-command.ts index 87d6faa..600bb28 100644 --- a/src/step-aware-command.ts +++ b/src/step-aware-command.ts @@ -270,11 +270,31 @@ export default abstract class extends RegistryAwareCommand { }) expectedFields.forEach(field => { if (field.type === FieldDefinition.Type.ANYNONSCALAR || field.type === FieldDefinition.Type.MAP) { - prompts.next({ - name: `:internal:confirm:${field.key}`, - message: `Add ${field.key} fields?`, - type: 'confirm' - }) + if (field.optionality === FieldDefinition.Optionality.OPTIONAL) { + prompts.next({ + name: `:internal:confirm:${field.key}`, + message: `Add ${field.key} fields?`, + type: 'confirm' + }) + } else { + prompts.next({ + name: `nonscalar.${field.key}.key`, + message: `${field.key} object key`, + type: 'input', + default: field.optionality === FieldDefinition.Optionality.OPTIONAL ? optionalMsg : null, + }) + prompts.next({ + name: `nonscalar.${field.key}.value`, + message: `${field.key} object value`, + type: 'input', + default: field.optionality === FieldDefinition.Optionality.OPTIONAL ? optionalMsg : null, + }) + prompts.next({ + name: ':internal:confirm:', + message: `Add another ${field.key} field?`, + type: 'confirm' + }) + } hasObjectNeed = true } else { prompts.next({