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

Commit 24c3c3f

Browse files
author
Simon Stone
authored
Environment variables cannot start REST server (#603)
1 parent 87bc11e commit 24c3c3f

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

packages/composer-rest-server/cli.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ const Util = require('./lib/util');
2626
const yargs = require('yargs')
2727
.wrap(null)
2828
.usage('Usage: $0 [options]')
29-
.option('n', { alias: 'businessNetworkName', describe: 'The business network identifier', type: 'string', default: process.env.COMPOSER_BUSINESS_NETWORK })
3029
.option('p', { alias: 'connectionProfileName', describe: 'The connection profile name', type: 'string', default: process.env.COMPOSER_CONNECTION_PROFILE })
30+
.option('n', { alias: 'businessNetworkName', describe: 'The business network identifier', type: 'string', default: process.env.COMPOSER_BUSINESS_NETWORK })
3131
.option('i', { alias: 'enrollId', describe: 'The enrollment ID of the user', type: 'string', default: process.env.COMPOSER_ENROLLMENT_ID })
3232
.option('s', { alias: 'enrollSecret', describe: 'The enrollment secret of the user', type: 'string', default: process.env.COMPOSER_ENROLLMENT_SECRET })
3333
.option('N', { alias: 'namespaces', describe: 'Use namespaces if conflicting types exist', type: 'string', default: process.env.COMPOSER_NAMESPACES || 'always', choices: ['always', 'required', 'never'] })
@@ -37,9 +37,16 @@ const yargs = require('yargs')
3737
.alias('h', 'help')
3838
.argv;
3939

40-
// see if we need to run interactively
40+
// See if we need to run interactively.
41+
// We check to see if no command line arguments have been supplied,
42+
// and then check to see that none of the required arguments have
43+
// been supplied via environment variables have been specified either.
44+
const interactive = process.argv.slice(2).length === 0 && // No command line arguments supplied.
45+
['n', 'p', 'i', 's'].every((flag) => {
46+
return yargs[flag] === undefined;
47+
});
4148
let promise;
42-
if (process.argv.slice(2).length === 0) {
49+
if (interactive) {
4350
// Gather some args interactively
4451
clear();
4552
console.log(

packages/composer-rest-server/test/cli.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ describe('composer-rest-server CLI unit tests', () => {
3838
sandbox.stub(process, 'exit');
3939
sandbox.spy(console, 'log');
4040
sandbox.spy(console, 'error');
41+
Object.keys(process.env).forEach((key) => {
42+
if (key.match(/^COMPOSER_/)) {
43+
delete process.env[key];
44+
}
45+
});
4146
});
4247

4348
afterEach(() => {

0 commit comments

Comments
 (0)