From 9fe436860255fc48efc4fcf7108f02a5d548e6ed Mon Sep 17 00:00:00 2001 From: Tobias Lohr Date: Wed, 17 Jul 2019 13:43:55 +0200 Subject: [PATCH] #49 remove sandbox:get and merge functionality into sandbox:list with option -s,--sandbox --- README.md | 1 - bin/test-cli.sh | 47 +++++++++++--------- cli.js | 111 +++++++++++++++++++++++------------------------- 3 files changed, 81 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index 3130e14f..b7aed488 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,6 @@ Use `sfcc-ci --help` to get started and see the list of commands available: sandbox:realm:update [options] Update realm settings sandbox:list [options] List all available sandboxes sandbox:create [options] Create a new sandbox - sandbox:get [options] Get detailed information about a sandbox sandbox:update [options] Update a sandbox sandbox:start [options] Start a sandbox sandbox:stop [options] Stop a sandbox diff --git a/bin/test-cli.sh b/bin/test-cli.sh index 3435f7a9..876bf9b0 100755 --- a/bin/test-cli.sh +++ b/bin/test-cli.sh @@ -383,17 +383,17 @@ fi # grab some sandbox details for next set of tests TEST_NEW_SANDBOX_ID=`echo $TEST_NEW_SANDBOX_RESULT | jq '.sandbox.id' -r` TEST_NEW_SANDBOX_INSTANCE=`echo $TEST_NEW_SANDBOX_RESULT | jq '.sandbox.instance' -r` -TEST_NEW_SANDBOX_HOST=`node ./cli.js sandbox:get --sandbox $TEST_NEW_SANDBOX_ID --host` +TEST_NEW_SANDBOX_HOST=`node ./cli.js sandbox:list --sandbox $TEST_NEW_SANDBOX_ID --host` if [ "$ARG_HOST" = "" ]; then ARG_HOST=$TEST_NEW_SANDBOX_HOST fi ############################################################################### -###### Testing ´sfcc-ci sandbox:get´ +###### Testing ´sfcc-ci sandbox:list´ with option ´-s,--sandbox´ ############################################################################### -echo "Testing command ´sfcc-ci sandbox:get´ (expected to fail):" +echo "Testing command ´sfcc-ci sandbox:get´ (unknown, expected to fail):" node ./cli.js sandbox:get if [ $? -eq 1 ]; then echo -e "\t> OK" @@ -402,8 +402,8 @@ else exit 1 fi -echo "Testing command ´sfcc-ci sandbox:get --sandbox ´ (expected to fail):" -node ./cli.js sandbox:get --sandbox INVALID_ID +echo "Testing command ´sfcc-ci sandbox:list --sandbox´ (expected to fail):" +node ./cli.js sandbox:list --sandbox if [ $? -eq 1 ]; then echo -e "\t> OK" else @@ -411,8 +411,17 @@ else exit 1 fi -echo "Testing command ´sfcc-ci sandbox:get --sandbox ´:" -node ./cli.js sandbox:get --sandbox $TEST_NEW_SANDBOX_ID +echo "Testing command ´sfcc-ci sandbox:list --sandbox ´ (expected to fail):" +node ./cli.js sandbox:list --sandbox INVALID_ID +if [ $? -eq 1 ]; then + echo -e "\t> OK" +else + echo -e "\t> FAILED" + exit 1 +fi + +echo "Testing command ´sfcc-ci sandbox:list --sandbox ´:" +node ./cli.js sandbox:list --sandbox $TEST_NEW_SANDBOX_ID if [ $? -eq 0 ]; then echo -e "\t> OK" else @@ -420,8 +429,8 @@ else exit 1 fi -echo "Testing command ´sfcc-ci sandbox:get --sandbox --json´:" -node ./cli.js sandbox:get --sandbox $TEST_NEW_SANDBOX_ID --json +echo "Testing command ´sfcc-ci sandbox:list --sandbox --json´:" +node ./cli.js sandbox:list --sandbox $TEST_NEW_SANDBOX_ID --json if [ $? -eq 0 ]; then echo -e "\t> OK" else @@ -429,8 +438,8 @@ else exit 1 fi -echo "Testing command ´sfcc-ci sandbox:get --sandbox ´ (using - as id):" -node ./cli.js sandbox:get --sandbox $ARG_SANDBOX_REALM"_"$TEST_NEW_SANDBOX_INSTANCE +echo "Testing command ´sfcc-ci sandbox:list --sandbox ´ (using - as id):" +node ./cli.js sandbox:list --sandbox $ARG_SANDBOX_REALM"_"$TEST_NEW_SANDBOX_INSTANCE if [ $? -eq 0 ]; then echo -e "\t> OK" else @@ -438,8 +447,8 @@ else exit 1 fi -echo "Testing command ´sfcc-ci sandbox:get --sandbox --host´:" -node ./cli.js sandbox:get --sandbox $TEST_NEW_SANDBOX_ID --host +echo "Testing command ´sfcc-ci sandbox:list --sandbox --host´:" +node ./cli.js sandbox:list --sandbox $TEST_NEW_SANDBOX_ID --host if [ $? -eq 0 ]; then echo -e "\t> OK" else @@ -447,8 +456,8 @@ else exit 1 fi -echo "Testing command ´sfcc-ci sandbox:get --sandbox --show-usage´:" -node ./cli.js sandbox:get --sandbox $TEST_NEW_SANDBOX_ID --show-usage +echo "Testing command ´sfcc-ci sandbox:list --sandbox --show-usage´:" +node ./cli.js sandbox:list --sandbox $TEST_NEW_SANDBOX_ID --show-usage if [ $? -eq 0 ]; then echo -e "\t> OK" else @@ -456,8 +465,8 @@ else exit 1 fi -echo "Testing command ´sfcc-ci sandbox:get --sandbox --show-operations´:" -node ./cli.js sandbox:get --sandbox $TEST_NEW_SANDBOX_ID --show-operations +echo "Testing command ´sfcc-ci sandbox:list --sandbox --show-operations´:" +node ./cli.js sandbox:list --sandbox $TEST_NEW_SANDBOX_ID --show-operations if [ $? -eq 0 ]; then echo -e "\t> OK" else @@ -465,8 +474,8 @@ else exit 1 fi -echo "Testing command ´sfcc-ci sandbox:get --sandbox --show-settings´:" -node ./cli.js sandbox:get --sandbox $TEST_NEW_SANDBOX_ID --show-settings +echo "Testing command ´sfcc-ci sandbox:list --sandbox --show-settings´:" +node ./cli.js sandbox:list --sandbox $TEST_NEW_SANDBOX_ID --show-settings if [ $? -eq 0 ]; then echo -e "\t> OK" else diff --git a/cli.js b/cli.js index b0705f3f..18ad0829 100755 --- a/cli.js +++ b/cli.js @@ -172,19 +172,70 @@ program program .command('sandbox:list') - .description('List all available sandboxes') + .description('List available sandboxes and detailed information') .option('-j, --json','Formats the output in json') .option('-S, --sortby ', 'Sort by specifying any field') + .option('-s, --sandbox ','sandbox to get details for') + .option('-h, --host','Return only the host name of the sandbox') + .option('-O, --open','Opens a browser with the Business Manager on the sandbox') + .option('--show-operations','Display operations performed') + .option('--show-usage','Display detailed usage information') + .option('--show-settings','Display settings applied') .action(function(options) { var asJson = ( options.json ? options.json : false ); var sortby = ( options.sortby ? options.sortby : null ); - require('./lib/sandbox').cli.list(asJson, sortby); + var sandbox_id = ( options.sandbox ? options.sandbox : null ); + + if (!sandbox_id) { + // list possibly multiple sandboxes + require('./lib/sandbox').cli.list(asJson, sortby); + return; + } + // otherwise return details for a single sandbox + // always assume it is a sandbox id + var spec = { id : sandbox_id }; + // check if we have to lookup the sandbox by realm and instance + var split = sandbox_id.split(/[-_]/); + if (split.length === 2) { + spec['realm'] = split[0]; + spec['instance'] = split[1]; + } + + var hostOnly = ( options.host ? options.host : false ); + var openBrowser = ( options.open ? options.open : false ); + var showOperations = ( options.showOperations ? options.showOperations : false ); + var showUsage = ( options.showUsage ? options.showUsage : false ); + var showSettings = ( options.showSettings ? options.showSettings : false ); + require('./lib/sandbox').cli.get(spec, asJson, hostOnly, openBrowser, showOperations, showUsage, showSettings); }).on('--help', function() { console.log(''); + console.log(' Details:'); + console.log(); + console.log(' Use this command to list either all available sandboxes or show details of a single'); + console.log(' sandbox. Use option -s,--sandbox to request details of a single sandbox, otherwise'); + console.log(' all sandboxes, the user is eligible to manage are being returned. The sandbox to lookup') + console.log(' must be identified by its id. Use may use `sfcc-ci sandbox:list` without option --sandbox to'); + console.log(' explore all your sandboxes.'); + console.log(); + console.log(' You can also pass the realm and the instance (e.g. zzzz-s01) as as handy alternative'); + console.log(' to the long uuid.'); + console.log(); + console.log(' Use --show-usage to display detailed usage information, --show-operations to get a list of'); + console.log(' previous operations executed on the sandbox, --show-settings to return the settings initially'); + console.log(' applied to the sandbox during creation.'); + console.log(); console.log(' Examples:'); console.log(); console.log(' $ sfcc-ci sandbox:list'); + console.log(' $ sfcc-ci sandbox:list --sortby createdBy'); console.log(' $ sfcc-ci sandbox:list --json'); + console.log(' $ sfcc-ci sandbox:list --sandbox my-sandbox-id'); + console.log(' $ sfcc-ci sandbox:list -s my-sandbox-id -j'); + console.log(' $ sfcc-ci sandbox:list -s my-sandbox-id -h'); + console.log(' $ sfcc-ci sandbox:list -s my-sandbox-id -O'); + console.log(' $ sfcc-ci sandbox:list -s my-sandbox-id --show-usage'); + console.log(' $ sfcc-ci sandbox:list -s my-sandbox-id --show-operations'); + console.log(' $ sfcc-ci sandbox:list -s my-sandbox-id --show-settings'); console.log(); }); @@ -242,62 +293,6 @@ program console.log(); }); -program - .command('sandbox:get') - .description('Get detailed information about a sandbox') - .option('-s, --sandbox ','sandbox to get details for') - .option('-j, --json','Formats the output in json') - .option('-h, --host','Return the host name of the sandbox') - .option('-O, --open','Opens a browser with the Business Manager on the sandbox') - .option('--show-operations','Display operations performed') - .option('--show-usage','Display detailed usage information') - .option('--show-settings','Display settings applied') - .action(function(options) { - var sandbox_id = ( options.sandbox ? options.sandbox : null ); - if (!sandbox_id) { - this.missingArgument('sandbox'); - return; - } - // always assume it is a sandbox id - var spec = { id : sandbox_id }; - // check if we have to lookup the sandbox by realm and instance - var split = sandbox_id.split(/[-_]/); - if (split.length === 2) { - spec['realm'] = split[0]; - spec['instance'] = split[1]; - } - var asJson = ( options.json ? options.json : false ); - var hostOnly = ( options.host ? options.host : false ); - var openBrowser = ( options.open ? options.open : false ); - var showOperations = ( options.showOperations ? options.showOperations : false ); - var showUsage = ( options.showUsage ? options.showUsage : false ); - var showSettings = ( options.showSettings ? options.showSettings : false ); - require('./lib/sandbox').cli.get(spec, asJson, hostOnly, openBrowser, showOperations, showUsage, showSettings); - }).on('--help', function() { - console.log(''); - console.log(' Details:'); - console.log(); - console.log(' The sandbox to lookup must be identified by its id. Use may use `sfcc-ci sandbox:list` to'); - console.log(' identify the id of your sandboxes.'); - console.log(); - console.log(' You can also pass the realm and the instance (e.g. zzzz-s01) as .'); - console.log(); - console.log(' Use --show-usage to display detailed usage information, --show-operations to get a list of'); - console.log(' previous operations executed on the sandbox, --show-settings to return the settings initially'); - console.log(' applied to the sandbox during creation.'); - console.log(''); - console.log(' Examples:'); - console.log(); - console.log(' $ sfcc-ci sandbox:get --sandbox my-sandbox-id'); - console.log(' $ sfcc-ci sandbox:get -s my-sandbox-id -j'); - console.log(' $ sfcc-ci sandbox:get -s my-sandbox-id -h'); - console.log(' $ sfcc-ci sandbox:get -s my-sandbox-id -O'); - console.log(' $ sfcc-ci sandbox:get -s my-sandbox-id --show-usage'); - console.log(' $ sfcc-ci sandbox:get -s my-sandbox-id --show-operations'); - console.log(' $ sfcc-ci sandbox:get -s my-sandbox-id --show-settings'); - console.log(); - }); - program .command('sandbox:update') .option('-s, --sandbox ','sandbox to update')