Skip to content

Commit 877a97f

Browse files
authored
Update cli.js
1 parent 3858ebe commit 877a97f

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

cli.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const deployStack = function (options) {
163163
const descParam = docYaml.Parameters[param].Description
164164
const allowedValues = docYaml.Parameters[param].AllowedValues
165165
const options = Object.keys(stackParamteres).map(x => `${x} = ${stackParamteres[x]}`)
166-
const index = readlineSync.keyInSelect(allowedValues || options, `Select a value for ${CPROMPT}${param}${CRESET} parameter (${descParam || ''}) ?`, {
166+
const index = readlineSync.keyInSelect(allowedValues || options, `Select a value for ${CPROMPT}${param}${CRESET} parameter (${descParam || ''}) ?`, {
167167
cancel: allowedValues ? `${CBRIGHT}None${CRESET} - (No change)` : `${CBRIGHT}Manual enter a value${CRESET} - (Continue)`
168168
})
169169
if (index >= 0) {
@@ -634,7 +634,7 @@ const showAvailableStacks = (options, promptDescription) => {
634634

635635
showBoxBanner()
636636

637-
var argv = require('yargs').usage('simplify-cli init | register | login | logout | upgrade | create | deploy | destroy | list [options]')
637+
var argv = require('yargs').usage('simplify-cli init | regiter | login | logout | upgrade | create | deploy | destroy | list [options]')
638638
.string('help').describe('help', 'Display Help for a specific command')
639639
.string('name').describe('name', 'Specify a name for the created project')
640640
.string('template').describe('template', 'Init nodejs or python template')
@@ -797,20 +797,21 @@ const processCLI = function (cmdRun, session) {
797797
"us-east-2 (N. Virginia)", "us-east-1 (Ohio)", "us-west-1 (N. California)",
798798
"eu-west-1 (Ireland)", "eu-central-1 (Frankfurt)", "eu-west-3 (Paris)",
799799
"ap-northeast-1 (Tokyo)", "ap-southeast-2 (Sydney)", "ap-southeast-1 (Singapore)"
800-
], ` - ${CPROMPT}Choose your AWS Region?${CRESET} `, { cancel: `${CBRIGHT}others${CRESET} (Enter manually)`})
800+
], ` - ${CPROMPT}Choose your AWS Region?${CRESET} `, { cancel: `${CBRIGHT}others${CRESET} (Enter manually)` })
801801
if (regionIndex == -1) {
802802
options.DEPLOYMENT_REGION = readlineSync.question(` - ${CPROMPT}What is your AWS Region?${CRESET} (${process.env.DEPLOYMENT_REGION || 'us-east-1'}) `) || `${process.env.DEPLOYMENT_REGION || 'us-east-1'}`
803803
} else {
804804
options.DEPLOYMENT_REGION = REGIONS[regionIndex]
805805
console.log(`\n *`, `Your have just selected the ${CBRIGHT}${options.DEPLOYMENT_REGION}${CRESET} region \n`)
806806
}
807+
simplify.consoleWithMessage(opName, "Inspect AWS AccountID...")
807808
exec(`aws sts get-caller-identity --profile ${options.DEPLOYMENT_PROFILE} --query "Account" --output=text`, (err, stdout, stderr) => {
808809
if (!err) {
809810
options.DEPLOYMENT_ACCOUNT = readlineSync.question(` - ${CPROMPT}Confirm your AWS AccountId?${CRESET} (${stdout.trim()}) `) || `${stdout.trim()}`
810811
} else {
811812
options.DEPLOYMENT_ACCOUNT = readlineSync.question(` - ${CPROMPT}What is your AWS AccountId?${CRESET} (${process.env.DEPLOYMENT_ACCOUNT || 'Enter a valid AccountId'}) `) || `${process.env.DEPLOYMENT_ACCOUNT || ''}`
812813
}
813-
verifyAccountAccess(options, callback, function(error) {
814+
verifyAccountAccess(options, callback, function (error) {
814815
simplify.consoleWithErrors(`${opName}-INIT`, `${error}`)
815816
})
816817
})
@@ -857,34 +858,41 @@ const processCLI = function (cmdRun, session) {
857858
}
858859
})
859860
}
861+
simplify.consoleWithMessage(opName, "Checking AWS-CLI/2...")
860862
exec(`aws --version`, (err, stdout, stderr) => {
861-
if (err) {
862-
console.log(`\n *`, `Missing awscli installed in your computer. Refer: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html \n`)
863+
if (err || stdout.startsWith("aws-cli/1.")) {
864+
if (stdout.startsWith("aws-cli/1.")) {
865+
console.log(`\n *`, `Need an upgrade to aws-cli/2 library. Refer: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html \n`)
866+
} else {
867+
console.log(`\n *`, `Missing aws-cli/2 installed in your computer. Refer: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html \n`)
868+
}
863869
} else {
864870
let initOptions = {
865871
PROJECT_NAME: readlineSync.question(` - ${CPROMPT}Choose a Project name?${CRESET} (${process.env.PROJECT_NAME || 'starwars'}) `) || `${process.env.PROJECT_NAME || 'starwars'}`,
866872
DEPLOYMENT_BUCKET: readlineSync.question(` - ${CPROMPT}Choose an S3 Bucket name?${CRESET} (${process.env.DEPLOYMENT_BUCKET || 'starwars-0920'}) `) || `${process.env.DEPLOYMENT_BUCKET || 'starwars-0920'}`,
867873
DEPLOYMENT_ENV: readlineSync.question(` - ${CPROMPT}Choose an Environment?${CRESET} (${process.env.DEPLOYMENT_ENV || 'demo'}) `) || `${process.env.DEPLOYMENT_ENV || 'demo'}`
868874
}
875+
simplify.consoleWithMessage(opName, "Checking Installed Profiles...")
869876
exec('aws configure list-profiles', (err, stdout, stderr) => {
870877
if (err) {
878+
console.log(err)
871879
simplify.consoleWithErrors(`${opName}-INIT`, `${err}`)
872880
} else {
873881
const profileItems = stdout.split('\n').filter(x => x)
874882
const selectedIndex = initOptions.DEPLOYMENT_PROFILE = readlineSync.keyInSelect(profileItems,
875883
` - ${CPROMPT}What is your AWS Profile?${CRESET}`,
876884
{ cancel: `I want to setup a new AWS Profile` })
877885
if (selectedIndex == -1) {
878-
setupProfile(initOptions, function(options) {
879-
setupAccountId(options, function(options) {
886+
setupProfile(initOptions, function (options) {
887+
setupAccountId(options, function (options) {
880888
createStackOnInit(options, argv.location, process.env)
881889
console.log(`\n *`, `Type '--help' with CREATE to find more: simplify-cli create --help \n`)
882890
})
883891
})
884892
} else {
885893
initOptions.DEPLOYMENT_PROFILE = profileItems[selectedIndex]
886894
console.log(`\n *`, `Your have just selected the ${CBRIGHT}${initOptions.DEPLOYMENT_PROFILE}${CRESET} profile \n`)
887-
setupAccountId(initOptions, function(options) {
895+
setupAccountId(initOptions, function (options) {
888896
createStackOnInit(options, argv.location, process.env)
889897
console.log(`\n *`, `Type '--help' with CREATE to find more: simplify-cli create --help \n`)
890898
})

0 commit comments

Comments
 (0)