Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Environment variables cannot start REST server (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Stone authored Apr 3, 2017
1 parent 87bc11e commit 24c3c3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/composer-rest-server/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const Util = require('./lib/util');
const yargs = require('yargs')
.wrap(null)
.usage('Usage: $0 [options]')
.option('n', { alias: 'businessNetworkName', describe: 'The business network identifier', type: 'string', default: process.env.COMPOSER_BUSINESS_NETWORK })
.option('p', { alias: 'connectionProfileName', describe: 'The connection profile name', type: 'string', default: process.env.COMPOSER_CONNECTION_PROFILE })
.option('n', { alias: 'businessNetworkName', describe: 'The business network identifier', type: 'string', default: process.env.COMPOSER_BUSINESS_NETWORK })
.option('i', { alias: 'enrollId', describe: 'The enrollment ID of the user', type: 'string', default: process.env.COMPOSER_ENROLLMENT_ID })
.option('s', { alias: 'enrollSecret', describe: 'The enrollment secret of the user', type: 'string', default: process.env.COMPOSER_ENROLLMENT_SECRET })
.option('N', { alias: 'namespaces', describe: 'Use namespaces if conflicting types exist', type: 'string', default: process.env.COMPOSER_NAMESPACES || 'always', choices: ['always', 'required', 'never'] })
Expand All @@ -37,9 +37,16 @@ const yargs = require('yargs')
.alias('h', 'help')
.argv;

// see if we need to run interactively
// See if we need to run interactively.
// We check to see if no command line arguments have been supplied,
// and then check to see that none of the required arguments have
// been supplied via environment variables have been specified either.
const interactive = process.argv.slice(2).length === 0 && // No command line arguments supplied.
['n', 'p', 'i', 's'].every((flag) => {
return yargs[flag] === undefined;
});
let promise;
if (process.argv.slice(2).length === 0) {
if (interactive) {
// Gather some args interactively
clear();
console.log(
Expand Down
5 changes: 5 additions & 0 deletions packages/composer-rest-server/test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ describe('composer-rest-server CLI unit tests', () => {
sandbox.stub(process, 'exit');
sandbox.spy(console, 'log');
sandbox.spy(console, 'error');
Object.keys(process.env).forEach((key) => {
if (key.match(/^COMPOSER_/)) {
delete process.env[key];
}
});
});

afterEach(() => {
Expand Down

0 comments on commit 24c3c3f

Please sign in to comment.