Skip to content

Commit

Permalink
#49 remove sandbox:get and merge functionality into sandbox:list with…
Browse files Browse the repository at this point in the history
… option -s,--sandbox <id>
  • Loading branch information
tobiaslohr committed Jul 17, 2019
1 parent cdaefdb commit 9fe4368
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 78 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 28 additions & 19 deletions bin/test-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -402,71 +402,80 @@ else
exit 1
fi

echo "Testing command ´sfcc-ci sandbox:get --sandbox <INVALID_ID>´ (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
echo -e "\t> FAILED"
exit 1
fi

echo "Testing command ´sfcc-ci sandbox:get --sandbox <sandbox>´:"
node ./cli.js sandbox:get --sandbox $TEST_NEW_SANDBOX_ID
echo "Testing command ´sfcc-ci sandbox:list --sandbox <INVALID_ID>´ (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 <sandbox>´:"
node ./cli.js sandbox:list --sandbox $TEST_NEW_SANDBOX_ID
if [ $? -eq 0 ]; then
echo -e "\t> OK"
else
echo -e "\t> FAILED"
exit 1
fi

echo "Testing command ´sfcc-ci sandbox:get --sandbox <sandbox> --json´:"
node ./cli.js sandbox:get --sandbox $TEST_NEW_SANDBOX_ID --json
echo "Testing command ´sfcc-ci sandbox:list --sandbox <sandbox> --json´:"
node ./cli.js sandbox:list --sandbox $TEST_NEW_SANDBOX_ID --json
if [ $? -eq 0 ]; then
echo -e "\t> OK"
else
echo -e "\t> FAILED"
exit 1
fi

echo "Testing command ´sfcc-ci sandbox:get --sandbox <sandbox>´ (using <realm>-<instance> as id):"
node ./cli.js sandbox:get --sandbox $ARG_SANDBOX_REALM"_"$TEST_NEW_SANDBOX_INSTANCE
echo "Testing command ´sfcc-ci sandbox:list --sandbox <sandbox>´ (using <realm>-<instance> as id):"
node ./cli.js sandbox:list --sandbox $ARG_SANDBOX_REALM"_"$TEST_NEW_SANDBOX_INSTANCE
if [ $? -eq 0 ]; then
echo -e "\t> OK"
else
echo -e "\t> FAILED"
exit 1
fi

echo "Testing command ´sfcc-ci sandbox:get --sandbox <sandbox> --host´:"
node ./cli.js sandbox:get --sandbox $TEST_NEW_SANDBOX_ID --host
echo "Testing command ´sfcc-ci sandbox:list --sandbox <sandbox> --host´:"
node ./cli.js sandbox:list --sandbox $TEST_NEW_SANDBOX_ID --host
if [ $? -eq 0 ]; then
echo -e "\t> OK"
else
echo -e "\t> FAILED"
exit 1
fi

echo "Testing command ´sfcc-ci sandbox:get --sandbox <sandbox> --show-usage´:"
node ./cli.js sandbox:get --sandbox $TEST_NEW_SANDBOX_ID --show-usage
echo "Testing command ´sfcc-ci sandbox:list --sandbox <sandbox> --show-usage´:"
node ./cli.js sandbox:list --sandbox $TEST_NEW_SANDBOX_ID --show-usage
if [ $? -eq 0 ]; then
echo -e "\t> OK"
else
echo -e "\t> FAILED"
exit 1
fi

echo "Testing command ´sfcc-ci sandbox:get --sandbox <sandbox> --show-operations´:"
node ./cli.js sandbox:get --sandbox $TEST_NEW_SANDBOX_ID --show-operations
echo "Testing command ´sfcc-ci sandbox:list --sandbox <sandbox> --show-operations´:"
node ./cli.js sandbox:list --sandbox $TEST_NEW_SANDBOX_ID --show-operations
if [ $? -eq 0 ]; then
echo -e "\t> OK"
else
echo -e "\t> FAILED"
exit 1
fi

echo "Testing command ´sfcc-ci sandbox:get --sandbox <sandbox> --show-settings´:"
node ./cli.js sandbox:get --sandbox $TEST_NEW_SANDBOX_ID --show-settings
echo "Testing command ´sfcc-ci sandbox:list --sandbox <sandbox> --show-settings´:"
node ./cli.js sandbox:list --sandbox $TEST_NEW_SANDBOX_ID --show-settings
if [ $? -eq 0 ]; then
echo -e "\t> OK"
else
Expand Down
111 changes: 53 additions & 58 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sortby>', 'Sort by specifying any field')
.option('-s, --sandbox <id>','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 <id> 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();
});

Expand Down Expand Up @@ -242,62 +293,6 @@ program
console.log();
});

program
.command('sandbox:get')
.description('Get detailed information about a sandbox')
.option('-s, --sandbox <id>','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 <id>.');
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 <id>','sandbox to update')
Expand Down

0 comments on commit 9fe4368

Please sign in to comment.