Skip to content

Commit

Permalink
Allow running multiple actions in a row with a single CLI call
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed May 31, 2017
1 parent 603165b commit 63254db
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Medic Project Configurer

medic-conf example-project http://admin:pass@localhost:5984

## Perform specific action
## Perform specific action(s)

medic-config <action> example-project http://admin:pass@localhost:5984
medic-config example-project http://admin:pass@localhost:5984 <...action>

The list of available actions can be seen in [`supported-actions.js`](https://github.com/alxndrsn/medic-configurer/blob/master/src/cli/supported-actions.js).

Expand Down
48 changes: 24 additions & 24 deletions bin/medic-conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@
const usage = require('../src/cli/usage');
const supportedActions = require('../src/cli/supported-actions');

switch(process.argv.length) {
case 4: {
const project = process.argv[2];
const instanceUrl = process.argv[3];
const couchUrl = `${instanceUrl}/medic`;
const args = process.argv.slice(2);
if(args.length < 2) {
usage();
process.exit(1);
}

return require('../src/cli/all.js')(project, couchUrl);
}
const project = args[0];
const instanceUrl = args[1];
const couchUrl = `${instanceUrl}/medic`;

case 5: {
const project = process.argv[3];
const instanceUrl = process.argv[4];
const couchUrl = `${instanceUrl}/medic`;
if(args.length === 2) {
return require('../src/cli/all.js')(project, couchUrl);
}

const action = process.argv[2];
const actions = args.slice(2);

if(supportedActions.includes(action)) {
const info = require('../src/lib/log').info;
if(!actions.every(a => supportedActions.includes(a))) {
error(`Unsupported action: ${a}`);
usage();
process.exit(1);
}

info(`Performing ${action} on ${instanceUrl}...`);
return require(`../src/fn/${action}`)(project, couchUrl)
.then(() => info(action, 'complete.'));
}
}
const info = require('../src/lib/log').info;

/* falls through */
default:
usage();
process.exit(1);
}
return actions.reduce((promiseChain, action) =>
promiseChain
.then(() => info('Starting action:', action, '...'))
.then(() => require(`../src/fn/${action}`)(project, couchUrl))
.then(() => info(action, 'complete')),
Promise.resolve());

0 comments on commit 63254db

Please sign in to comment.