@@ -12,20 +12,12 @@ const provider = require('simplify-sdk/provider');
1212const readlineSync = require ( 'readline-sync' ) ;
1313const { options } = require ( 'yargs' ) ;
1414const { exec } = require ( 'child_process' ) ;
15- const { authenticate, registerUser, confirmRegistration, getCurrentSession, userSignOut } = require ( './cognito' )
16- const PLAN_DEFINITIONS = {
17- "BASIC" : {
18- "Index" : 0 ,
19- "Version" : "Community" ,
20- "Description" : "FREE membership with community access to development resources" ,
21- "Subscription" : 0
22- } ,
23- "PREMIUM" : {
24- "Index" : 1 ,
25- "Version" : "Enterprise" ,
26- "Description" : "10$ per month with unlimited access to productionr ready resources" ,
27- "Subscription" : 10
28- }
15+ const { authenticate, registerUser, confirmRegistration, getCurrentSession, userSignOut } = require ( './cognito' ) ;
16+ const yargs = require ( 'yargs' ) ;
17+ const { PLAN_DEFINITIONS , ALLOWED_COMANDS , AVAILABLE_COMMANDS } = require ( './const' )
18+ const getOptionDesc = function ( cmdOpt , optName ) {
19+ const options = ( AVAILABLE_COMMANDS . find ( cmd => cmd . name == cmdOpt ) || { options : [ ] } ) . options
20+ return ( options . find ( opt => opt . name == optName ) || { desc : '' } ) . desc
2921}
3022var currentSubscription = "Basic"
3123var functionMeta = { lashHash256 : null }
@@ -634,33 +626,51 @@ const showAvailableStacks = (options, promptDescription) => {
634626
635627showBoxBanner ( )
636628
637- var argv = require ( 'yargs' ) . usage ( 'simplify-cli init | regiter | login | logout | upgrade | create | deploy | destroy | list [options]' )
638- . string ( 'help' ) . describe ( 'help' , 'Display Help for a specific command' )
639- . string ( 'name' ) . describe ( 'name' , 'Specify a name for the created project' )
640- . string ( 'template' ) . describe ( 'template' , 'Init nodejs or python template' )
641- . string ( 'data' ) . describe ( 'data' , 'Saved parameters in JSON file' ) . default ( 'data' , 'parameters.json' )
642- . string ( 'config' ) . alias ( 'c' , 'config' ) . describe ( 'config' , 'function configuration' ) . default ( 'config' , 'config.json' )
643- . string ( 'policy' ) . alias ( 'p' , 'policy' ) . describe ( 'policy' , 'function policy to attach' ) . default ( 'policy' , 'policy.json' )
644- . string ( 'role' ) . alias ( 'r' , 'role' ) . describe ( 'role' , 'function policy to attach' ) . default ( 'role' , 'role.json' )
645- . string ( 'source' ) . alias ( 's' , 'source' ) . describe ( 'source' , 'function source to deploy' ) . default ( 'source' , 'src' )
646- . string ( 'env' ) . alias ( 'e' , 'env' ) . describe ( 'env' , 'environment name' )
647- . string ( 'region' ) . describe ( 'region' , 'region name to deploy' )
648- . string ( 'exclude' ) . describe ( 'exclude' , 'files or folders to exclude for a zip' )
649- . string ( 'env-file' ) . describe ( 'env-file' , 'environment variable file' ) . default ( 'env-file' , '.env' )
650- . boolean ( 'update' ) . describe ( 'update' , 'force update function code' ) . default ( 'update' , false )
651- . boolean ( 'publish' ) . describe ( 'publish' , 'force publish with a version' ) . default ( 'publish' , false )
652- . boolean ( 'layer' ) . describe ( 'layer' , 'deploy source folder as layer' ) . default ( 'layer' , false )
653- . string ( 'location' ) . describe ( 'location' , 'stack folder to deploy' ) . default ( 'location' , '' )
654- . string ( 'stack' ) . describe ( 'stack' , 'stack name to deploy' )
655- . string ( 'function' ) . describe ( 'function' , 'function name to deploy' )
656- . string ( 'composer' ) . describe ( 'composer' , 'multistacks composer to deploy' )
657- . demandOption ( [ 'c' , 'p' , 's' ] ) . demandCommand ( 1 ) . argv ;
629+ var argv = require ( 'yargs' ) . usage ( 'simplify-cli command [options]' )
630+ . string ( 'help' ) . describe ( 'help' , 'display help for a specific command' )
631+ . string ( 'name' ) . describe ( 'name' , getOptionDesc ( 'create' , 'name' ) )
632+ . string ( 'template' ) . describe ( 'template' , getOptionDesc ( 'create' , 'template' ) )
633+ . string ( 'stack' ) . describe ( 'stack' , getOptionDesc ( 'deploy' , 'stack' ) )
634+ . string ( 'function' ) . describe ( 'function' , getOptionDesc ( 'deploy' , 'function' ) )
635+ . string ( 'location' ) . describe ( 'location' , getOptionDesc ( 'deploy' , 'location' ) ) . default ( 'location' , '' )
636+ . string ( 'parameters' ) . describe ( 'parameters' , getOptionDesc ( 'deploy' , 'parameters' ) ) . default ( 'parameters' , 'parameters.json' )
637+ . string ( 'config' ) . describe ( 'config' , 'function configuration' ) . default ( 'config' , 'config.json' )
638+ . string ( 'policy' ) . describe ( 'policy' , 'function policy to attach' ) . default ( 'policy' , 'policy.json' )
639+ . string ( 'role' ) . describe ( 'role' , 'function policy to attach' ) . default ( 'role' , 'role.json' )
640+ . string ( 'source' ) . describe ( 'source' , 'function source to deploy' ) . default ( 'source' , 'src' )
641+ . string ( 'env' ) . describe ( 'env' , 'environment name' )
642+ . string ( 'region' ) . describe ( 'region' , getOptionDesc ( 'deploy' , 'region' ) )
643+ . string ( 'dotenv' ) . describe ( 'dotenv' , getOptionDesc ( 'deploy' , 'dotenv' ) ) . default ( 'dotenv' , '.env' )
644+ . boolean ( 'update' ) . describe ( 'update' , getOptionDesc ( 'deploy' , 'update' ) ) . default ( 'update' , false )
645+ . boolean ( 'publish' ) . describe ( 'publish' , getOptionDesc ( 'deploy' , 'publish' ) ) . default ( 'publish' , false )
646+ . boolean ( 'layer' ) . describe ( 'layer' , getOptionDesc ( 'deploy' , 'layer' ) ) . default ( 'layer' , false )
647+ . demandCommand ( 0 ) . argv ;
658648
659649var cmdOPS = ( argv . _ [ 0 ] || 'list' ) . toUpperCase ( )
660650var optCMD = ( argv . _ . length > 1 ? argv . _ [ 1 ] : undefined )
661651var cmdArg = argv [ 'stack' ] || argv [ 'function' ] || optCMD
662652var cmdType = cmdArg ? fs . existsSync ( path . resolve ( argv . location , cmdArg , "template.yaml" ) ) ? "CF-Stack" : "Function" : undefined
663-
653+ if ( argv . _ . length == 0 ) {
654+ yargs . showHelp ( )
655+ console . log ( `\n` , ` * ${ CBRIGHT } Supported command list${ CRESET } :` , '\n' )
656+ AVAILABLE_COMMANDS . map ( ( cmd , idx ) => {
657+ console . log ( `\t- ${ CPROMPT } ${ cmd . name . toLowerCase ( ) } ${ CRESET } : ${ cmd . desc } ` )
658+ } )
659+ console . log ( `\n` )
660+ process . exit ( 0 )
661+ } else {
662+ if ( typeof argv [ 'help' ] !== 'undefined' ) {
663+ console . log ( `\n` , ` * ${ CBRIGHT } Supported options${ CRESET } :` , '\n' )
664+ const cmdResult = AVAILABLE_COMMANDS . find ( cmd => cmdOPS . toLowerCase ( ) == cmd . name )
665+ if ( cmdResult ) {
666+ cmdResult . options . map ( ( cmd , idx ) => {
667+ console . log ( `\t${ CPROMPT } --${ cmd . name . toLowerCase ( ) } ${ CRESET } : ${ cmd . desc } ` )
668+ } )
669+ }
670+ console . log ( `\n` )
671+ process . exit ( 0 )
672+ }
673+ }
664674const showSubscriptionPlan = function ( userSession ) {
665675 currentSubscription = ( userSession . getIdToken ( ) . payload [ `subscription` ] || 'Basic' )
666676 const currentVersion = PLAN_DEFINITIONS [ currentSubscription . toUpperCase ( ) ] . Version || 'Community'
@@ -679,8 +689,8 @@ const processCLI = function (cmdRun, session) {
679689 configStackName : cmdArg ,
680690 configStackFolder : argv . location ,
681691 envName : argv . env ,
682- envFile : argv [ 'env-file ' ] ,
683- dataFile : argv . data ,
692+ envFile : argv [ 'dotenv ' ] ,
693+ dataFile : argv . parameters ,
684694 roleFile : argv . role ,
685695 policyFile : argv . policy ,
686696 sourceDir : argv . source ,
@@ -693,7 +703,7 @@ const processCLI = function (cmdRun, session) {
693703 regionName : argv . region ,
694704 configFile : argv . config ,
695705 envName : argv . env ,
696- envFile : argv [ 'env-file ' ]
706+ envFile : argv [ 'dotenv ' ]
697707 } , `Available ${ CPROMPT } stack${ CRESET } and ${ CPROMPT } function${ CRESET } to deploy with command: simplify-cli deploy [--stack or --function] name` )
698708 }
699709
@@ -703,14 +713,14 @@ const processCLI = function (cmdRun, session) {
703713 regionName : argv . region ,
704714 configFile : argv . config ,
705715 envName : argv . env ,
706- envFile : argv [ 'env-file ' ] ,
716+ envFile : argv [ 'dotenv ' ] ,
707717 functionName : cmdArg ,
708718 withFunctionLayer : argv . layer
709719 } ) : destroyStack ) ( {
710720 regionName : argv . region ,
711721 configFile : argv . config ,
712722 envName : argv . env ,
713- envFile : argv [ 'env-file ' ] ,
723+ envFile : argv [ 'dotenv ' ] ,
714724 configStackFolder : argv . location ,
715725 configStackName : cmdArg
716726 } )
@@ -719,7 +729,7 @@ const processCLI = function (cmdRun, session) {
719729 regionName : argv . region ,
720730 configFile : argv . config ,
721731 envName : argv . env ,
722- envFile : argv [ 'env-file ' ]
732+ envFile : argv [ 'dotenv ' ]
723733 } , `Select a ${ CPROMPT } stack${ CRESET } or ${ CPROMPT } function${ CRESET } to destroy with command: simplify-cli destroy [--stack or --function] name` )
724734 }
725735 } else if ( cmdRun === "LOGOUT" ) {
@@ -774,7 +784,7 @@ const processCLI = function (cmdRun, session) {
774784 regionName : argv . region ,
775785 configFile : argv . config ,
776786 envName : argv . env ,
777- envFile : argv [ 'env-file ' ]
787+ envFile : argv [ 'dotenv ' ]
778788 } , `Deployed ${ CPROMPT } stacks${ CRESET } and ${ CPROMPT } functions${ CRESET } managed by Simplify CLI:` )
779789 } else if ( cmdRun === "INIT" ) {
780790 function verifyAccountAccess ( options , callback , errorHandler ) {
@@ -904,13 +914,10 @@ const processCLI = function (cmdRun, session) {
904914 } else if ( cmdRun === "CREATE" ) {
905915 const templateName = argv . template || optCMD
906916 if ( typeof templateName === "undefined" ) {
907- if ( typeof argv . help !== "undefined" ) {
908- showTemplates ( "basic/functions" , `\nCreate a function template: simplify-cli create [--template=]ShowLog | Detector\n` )
909- showTemplates ( "basic/stacks" , `\nOr create a deployment stack: simplify-cli create [--template=]CloudFront | CognitoUser...\n` )
910- console . log ( `\n *` , `Or fetch from YAML: simplify-cli create [--template=]https://github.com/awslabs/...template.yml \n` )
911- } else {
912- console . log ( `\n *` , `Missing a Template: simplify-cli create [--template=]Template \n` )
913- }
917+ console . log ( `\nMissing a Template: simplify-cli create [--template=]Template \n` )
918+ showTemplates ( "basic/functions" , `\nCreate a function template: simplify-cli create [--template=]ShowLog | Detector\n` )
919+ showTemplates ( "basic/stacks" , `\nOr create a deployment stack: simplify-cli create [--template=]CloudFront | CognitoUser...\n` )
920+ console . log ( `\n *` , `Or fetch from YAML: simplify-cli create [--template=]https://github.com/awslabs/...template.yml \n` )
914921 } else {
915922 createStackOnInit ( templateName , argv . location , process . env )
916923 }
@@ -919,7 +926,7 @@ const processCLI = function (cmdRun, session) {
919926 }
920927}
921928
922- if ( [ "INIT" , "LOGIN" , "REGISTER" ] . indexOf ( cmdOPS ) == - 1 ) {
929+ if ( ALLOWED_COMANDS . indexOf ( cmdOPS ) == - 1 ) {
923930 if ( ! fs . existsSync ( path . resolve ( argv . config || 'config.json' ) ) ) {
924931 console . log ( `\n` , `- ${ CPROMPT } This is not a valid environment${ CRESET } . You must create an environment first.` )
925932 console . log ( `\n` , `*` , `Create environment: \tsimplify-cli init` , `\n` )
@@ -942,6 +949,8 @@ if (["INIT", "LOGIN", "REGISTER"].indexOf(cmdOPS) == -1) {
942949 if ( [ "INIT" ] . indexOf ( cmdOPS ) == - 1 ) {
943950 const configInfo = JSON . parse ( fs . readFileSync ( path . resolve ( argv . config || 'config.json' ) ) )
944951 if ( configInfo . hasOwnProperty ( 'Profile' ) && configInfo . hasOwnProperty ( 'Region' ) && configInfo . hasOwnProperty ( 'Bucket' ) ) {
952+ console . log ( `\n` , ` * ${ CPROMPT } Opensource Support${ CRESET } : Community (FREE)` )
953+ console . log ( ` * ${ CPROMPT } Enterprise Support${ CRESET } : simplify-cli register` )
945954 processCLI ( cmdOPS )
946955 } else {
947956 console . log ( `\n` , `- ${ CPROMPT } This is not a valid environment${ CRESET } . The ${ argv . config || 'config.json' } is incorrect.` )
0 commit comments