Skip to content

Commit

Permalink
Merge pull request #743 from coralproject/change-org-name
Browse files Browse the repository at this point in the history
Added new cli-settings
  • Loading branch information
kgardnr authored Jul 7, 2017
2 parents db371d1 + 787c003 commit 3924ced
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
11 changes: 9 additions & 2 deletions bin/cli
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ const program = require('./commander');

program
.command('serve', 'serve the application')
.command('settings', 'interact with the application settings')
.command('assets', 'interact with assets')
.command('setup', 'setup the application')
.command('jobs', 'work with the job queues')
.command('token', 'work with the access tokens')
.command('users', 'work with the application auth')
.command('migration', 'provides utilities for migrating the database')
.command('plugins', 'provides utilities for interacting with the plugin system')
.command(
'plugins',
'provides utilities for interacting with the plugin system'
)
.parse(process.argv);

/**
Expand All @@ -25,7 +29,10 @@ program
* labled with the PID written out by the parent process.
*/
process.once('exit', () => {
if ((program.runningCommand.killed === false) && (program.runningCommand.exitCode === null)) {
if (
program.runningCommand.killed === false &&
program.runningCommand.exitCode === null
) {
program.runningCommand.kill('SIGINT');
}
});
59 changes: 59 additions & 0 deletions bin/cli-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env node

const program = require('./commander');
const inquirer = require('inquirer');
const mongoose = require('../services/mongoose');
const SettingsService = require('../services/settings');
const util = require('./util');

// Register the shutdown criteria.
util.onshutdown([() => mongoose.disconnect()]);

/**
* Change the organization name
*/
async function changeOrgName() {
try {
let settings = await SettingsService.retrieve();

let {organizationName} = await inquirer.prompt([
{
name: 'organizationName',
message: 'Organization Name',
default: settings.organizationName
}
]);

if (settings.organizationName !== organizationName) {
settings.organizationName = organizationName;

await SettingsService.update(settings);

console.log('Settings were updated.');
} else {
console.log('No update needed, no change was made.');
}
} catch (err) {
console.error(err);
util.shutdown(1);
}

util.shutdown();
}

//==============================================================================
// Setting up the program command line arguments.
//==============================================================================

program
.command('change-org-name')
.description('change the organization name')
.action(changeOrgName);

program.parse(process.argv);

// If there is no command listed, output help.
if (!process.argv.slice(2).length) {
program.outputHelp();
util.shutdown();
}

0 comments on commit 3924ced

Please sign in to comment.