Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/composer-rest-server/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const clear = require('clear');
const figlet = require('figlet');
const server = require('./server/server');
const Util = require('./lib/util');
let _ = require('lodash');

const yargs = require('yargs')
.wrap(null)
Expand All @@ -33,6 +34,14 @@ const yargs = require('yargs')
.option('N', { alias: 'namespaces', describe: 'Use namespaces if conflicting types exist', type: 'string', default: process.env.COMPOSER_NAMESPACES || 'always', choices: ['always', 'required', 'never'] })
.option('P', { alias: 'port', describe: 'The port to serve the REST API on', type: 'number', default: process.env.COMPOSER_PORT || undefined })
.option('S', { alias: 'security', describe: 'Enable security for the REST API', type: 'boolean', default: process.env.COMPOSER_SECURITY || false })
.alias('v', 'version')
.version(() => {
return getInfo('composer-rest-server')+getInfo('composer-cli')+
getInfo('composer-admin')+getInfo('composer-client')+
getInfo('composer-common')+getInfo('composer-runtime-hlf')+
getInfo('composer-connector-hlf')+getInfo('composer-runtime-hlfv1')+
getInfo('composer-connector-hlfv1');
})
.help('h')
.alias('h', 'help')
.argv;
Expand Down Expand Up @@ -130,3 +139,21 @@ module.exports = promise.then((composer) => {
console.error(error);
process.exit(1);
});

/**
* [getInfo description]
* @param {[type]} moduleName [description]
* @return {[type]} [description]
*/
function getInfo(moduleName) {

try{
let pjson = ((moduleName=== 'composer-rest-server') ? require('./package.json') : require(moduleName).version);
return _.padEnd(pjson.name,30) + ' v'+pjson.version+'\n';
}
catch (error){
// oh well - we'll just return a blank string
return '';
}

}
12 changes: 12 additions & 0 deletions packages/composer-rest-server/test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ describe('composer-rest-server CLI unit tests', () => {
sandbox.restore();
});

it('should call version and give the correct version', () => {
process.argv = [ process.argv0, 'cli.js', '-v' ];
delete require.cache[require.resolve('yargs')];
return proxyquire('../cli', {})
.then(() => {
// Meh
})
.catch((error) => {
error.should.be.null;
});
});

it('should call inquirer if no arguments specified and start the server', () => {
let listen = sinon.stub();
process.argv = [ process.argv0 ];
Expand Down