@@ -11,6 +11,7 @@ import { isCelExpression, resolveExpression } from "./cel";
1111import { FirebaseConfig } from "./args" ;
1212import { labels as secretLabels } from "../../gcp/secretManager" ;
1313import * as experiments from "../../experiments" ;
14+ import { marked } from "marked" ;
1415
1516// A convenience type containing options for Prompt's select
1617interface ListItem {
@@ -542,9 +543,11 @@ async function ensureSecret(
542543 }
543544 return ensureSecret ( secretParam , projectId , nonInteractive , force ) ;
544545 }
545- const promptMessage = `The value for this secret (${ secretParam . name } ) will be stored in Cloud Secret Manager (https://cloud.google.com/secret-manager/pricing) as ${ resourceId } . Enter ${ secretParam . format === "json" ? "a JSON value" : "a value" } for ${
546- secretParam . label || secretParam . name
547- } :`;
546+ const label = secretParam . label || secretParam . name ;
547+ const notice = `The value for this secret will be stored in Cloud Secret Manager (https://cloud.google.com/secret-manager/pricing) as ${ resourceId } .` ;
548+ const desc = secretParam . description ? `${ secretParam . description } ${ notice } ` : notice ;
549+ logger . info ( `\n${ clc . bold ( label ) } : ${ ( await marked ( desc ) ) . trim ( ) } ` ) ;
550+ const promptMessage = `Enter ${ secretParam . format === "json" ? "a JSON value" : "a value" } for ${ label } :` ;
548551 const secretValue = await password ( {
549552 message : promptMessage ,
550553 } ) ;
@@ -596,6 +599,14 @@ async function promptParam(
596599 projectId : string ,
597600 resolvedDefault ?: RawParamValue ,
598601) : Promise < ParamValue > {
602+ const label = param . label || param . name ;
603+ if ( param . description ) {
604+ logger . info ( `\n${ clc . bold ( label ) } : ${ ( await marked ( param . description ) ) . trim ( ) } ` ) ;
605+ } else {
606+ // Provide newline spacing between successive parameter prompts when there is no description to display.
607+ logger . info ( "" ) ;
608+ }
609+
599610 if ( param . type === "string" ) {
600611 const provided = await promptStringParam (
601612 param ,
@@ -629,46 +640,32 @@ async function promptList(
629640 const defaultToText : TextInput < string > = { text : { } } ;
630641 param . input = defaultToText ;
631642 }
632- let prompt : string ;
643+ const label = param . label || param . name ;
633644
634645 if ( isSelectInput ( param . input ) ) {
635646 throw new FirebaseError ( "List params cannot have non-list selector inputs" ) ;
636647 } else if ( isMultiSelectInput ( param . input ) ) {
637- prompt = `Select a value for ${ param . label || param . name } :` ;
638- if ( param . description ) {
639- prompt += ` \n(${ param . description } )` ;
640- }
641- prompt += "\nSelect an option with the arrow keys, and use Enter to confirm your choice. " ;
642648 return promptSelectMultiple < string > (
643- prompt ,
649+ `Select values for ${ label } :` ,
644650 param . input ,
645651 resolvedDefault ,
646652 param . input . multiSelect . nonEmpty ,
647653 ( res : string [ ] ) => res ,
648654 ) ;
649655 } else if ( isTextInput ( param . input ) ) {
650- prompt = `Enter a list of strings (delimiter: ${ param . delimiter ? param . delimiter : "," } ) for ${
651- param . label || param . name
652- } :`;
653- if ( param . description ) {
654- prompt += ` \n(${ param . description } )` ;
655- }
656+ const delimiter = param . delimiter ? param . delimiter : "," ;
656657 return promptText < string [ ] > (
657- prompt ,
658+ `Enter a list of strings (delimiter: ${ delimiter } ) for ${ label } :` ,
658659 param . input ,
659660 resolvedDefault ,
660661 param . input . text . nonEmpty ,
661662 ( res : string ) : string [ ] => {
662- return res . split ( param . delimiter || "," ) ;
663+ return res . split ( delimiter ) ;
663664 } ,
664665 ) ;
665666 } else if ( isResourceInput ( param . input ) ) {
666667 // N.B: The type system in the SDK currently doesn't allow a ResourceInput to be assigned to a ListParam, so this path is unreachable.
667- prompt = `Select values for ${ param . label || param . name } :` ;
668- if ( param . description ) {
669- prompt += ` \n(${ param . description } )` ;
670- }
671- return promptResourceStrings ( prompt , param . input , projectId , false ) ;
668+ return promptResourceStrings ( `Select values for ${ label } :` , param . input , projectId , false ) ;
672669 } else {
673670 assertExhaustive ( param . input ) ;
674671 }
@@ -683,24 +680,20 @@ async function promptBooleanParam(
683680 param . input = defaultToText ;
684681 }
685682 const isTruthyInput = ( res : string ) => [ "true" , "y" , "yes" , "1" ] . includes ( res . toLowerCase ( ) ) ;
686- let prompt : string ;
683+ const label = param . label || param . name ;
687684
688685 if ( isSelectInput ( param . input ) ) {
689- prompt = `Select a value for ${ param . label || param . name } :` ;
690- if ( param . description ) {
691- prompt += ` \n( ${ param . description } )` ;
692- }
693- prompt += "\nSelect an option with the arrow keys, and use Enter to confirm your choice. " ;
694- return promptSelect < boolean > ( prompt , param . input , resolvedDefault , isTruthyInput ) ;
686+ return promptSelect < boolean > (
687+ `Select a value for ${ label } :` ,
688+ param . input ,
689+ resolvedDefault ,
690+ isTruthyInput ,
691+ ) ;
695692 } else if ( isMultiSelectInput ( param . input ) ) {
696693 throw new FirebaseError ( "Non-list params cannot have multi selector inputs" ) ;
697694 } else if ( isTextInput ( param . input ) ) {
698- prompt = `Enter a boolean value for ${ param . label || param . name } :` ;
699- if ( param . description ) {
700- prompt += ` \n(${ param . description } )` ;
701- }
702695 return promptText < boolean > (
703- prompt ,
696+ `Enter a boolean value for ${ label } :` ,
704697 param . input ,
705698 resolvedDefault ,
706699 false , // enforceNonEmpty
@@ -722,30 +715,27 @@ async function promptStringParam(
722715 const defaultToText : TextInput < string > = { text : { } } ;
723716 param . input = defaultToText ;
724717 }
725- let prompt : string ;
718+ const label = param . label || param . name ;
726719
727720 if ( isResourceInput ( param . input ) ) {
728- prompt = `Select a value for ${ param . label || param . name } :` ;
729- if ( param . description ) {
730- prompt += ` \n(${ param . description } )` ;
731- }
732- return promptResourceString ( prompt , param . input , projectId , resolvedDefault ) ;
721+ return promptResourceString (
722+ `Select a value for ${ label } :` ,
723+ param . input ,
724+ projectId ,
725+ resolvedDefault ,
726+ ) ;
733727 } else if ( isMultiSelectInput ( param . input ) ) {
734728 throw new FirebaseError ( "Non-list params cannot have multi selector inputs" ) ;
735729 } else if ( isSelectInput ( param . input ) ) {
736- prompt = `Select a value for ${ param . label || param . name } :` ;
737- if ( param . description ) {
738- prompt += ` \n( ${ param . description } )` ;
739- }
740- prompt += "\nSelect an option with the arrow keys, and use Enter to confirm your choice. " ;
741- return promptSelect < string > ( prompt , param . input , resolvedDefault , ( res : string ) => res ) ;
730+ return promptSelect < string > (
731+ `Select a value for ${ label } :` ,
732+ param . input ,
733+ resolvedDefault ,
734+ ( res : string ) => res ,
735+ ) ;
742736 } else if ( isTextInput ( param . input ) ) {
743- prompt = `Enter a string value for ${ param . label || param . name } :` ;
744- if ( param . description ) {
745- prompt += ` \n(${ param . description } )` ;
746- }
747737 return promptText < string > (
748- prompt ,
738+ `Enter a string value for ${ label } :` ,
749739 param . input ,
750740 resolvedDefault ,
751741 param . input . text . nonEmpty ,
@@ -761,32 +751,28 @@ async function promptIntParam(param: IntParam, resolvedDefault?: number): Promis
761751 const defaultToText : TextInput < number > = { text : { } } ;
762752 param . input = defaultToText ;
763753 }
764- let prompt : string ;
754+ const label = param . label || param . name ;
765755
766756 if ( isSelectInput ( param . input ) ) {
767- prompt = `Select a value for ${ param . label || param . name } :` ;
768- if ( param . description ) {
769- prompt += ` \n( ${ param . description } )` ;
770- }
771- prompt += "\nSelect an option with the arrow keys, and use Enter to confirm your choice. " ;
772- return promptSelect ( prompt , param . input , resolvedDefault , ( res : string ) => {
773- if ( isNaN ( + res ) ) {
774- return { message : `" ${ res } " could not be converted to a number.` } ;
775- }
776- if ( res . includes ( "." ) ) {
777- return { message : ` ${ res } is not an integer value.` } ;
778- }
779- return + res ;
780- } ) ;
757+ return promptSelect (
758+ `Select a value for ${ label } :` ,
759+ param . input ,
760+ resolvedDefault ,
761+ ( res : string ) => {
762+ if ( isNaN ( + res ) ) {
763+ return { message : `" ${ res } " could not be converted to a number.` } ;
764+ }
765+ if ( res . includes ( "." ) ) {
766+ return { message : ` ${ res } is not an integer value.` } ;
767+ }
768+ return + res ;
769+ } ,
770+ ) ;
781771 } else if ( isMultiSelectInput ( param . input ) ) {
782772 throw new FirebaseError ( "Non-list params cannot have multi selector inputs" ) ;
783773 } else if ( isTextInput ( param . input ) ) {
784- prompt = `Enter an integer value for ${ param . label || param . name } :` ;
785- if ( param . description ) {
786- prompt += ` \n(${ param . description } )` ;
787- }
788774 return promptText < number > (
789- prompt ,
775+ `Enter an integer value for ${ label } :` ,
790776 param . input ,
791777 resolvedDefault ,
792778 param . input . text . nonEmpty ,
@@ -933,6 +919,7 @@ async function promptSelect<T extends RawParamValue>(
933919 const response = await select < string > ( {
934920 default : resolvedDefault as string ,
935921 message : prompt ,
922+ instructions : "(Use arrow keys to navigate, and Enter to confirm your choice)" ,
936923 choices : input . select . options . map ( ( option : SelectOptions < T > ) : ListItem => {
937924 return {
938925 checked : false ,
@@ -959,6 +946,7 @@ async function promptSelectMultiple<T extends string>(
959946 const response = await checkbox ( {
960947 default : resolvedDefault ,
961948 message : prompt ,
949+ instructions : "(Press Space to select, and Enter to confirm your choices)" ,
962950 choices : input . multiSelect . options . map ( ( option : SelectOptions < string > ) : ListItem => {
963951 return {
964952 checked : false ,
0 commit comments