Files
talk/bin/cli-assets
T
Wyatt Johnson b0f01cf00f Initial commit of asset queuing (#97)
* Initial commit of asset queuing

* Addresssing comments
2016-11-28 13:29:39 -05:00

77 lines
1.5 KiB
JavaScript
Executable File

#!/usr/bin/env node
/**
* Setup the debug paramater.
*/
process.env.DEBUG = process.env.TALK_DEBUG;
/**
* Module dependencies.
*/
const program = require('commander');
const pkg = require('../package.json');
const Table = require('cli-table');
const Asset = require('../models/asset');
const mongoose = require('../mongoose');
const util = require('../util');
// Register the shutdown criteria.
util.onshutdown([
() => mongoose.disconnect()
]);
/**
* Lists all the assets registered in the database.
*/
function listAssets() {
Asset
.find({})
.sort({'created_at': 1})
.then((asset) => {
let table = new Table({
head: [
'ID',
'Title',
'URL'
]
});
asset.forEach((asset) => {
table.push([
asset.id,
asset.title ? asset.title : '',
asset.url ? asset.url : ''
]);
});
console.log(table.toString());
util.shutdown();
})
.catch((err) => {
console.error(err);
util.shutdown(1);
});
}
//==============================================================================
// Setting up the program command line arguments.
//==============================================================================
program
.version(pkg.version);
program
.command('list')
.description('list all the assets in the database')
.action(listAssets);
program.parse(process.argv);
// If there is no command listed, output help.
if (!process.argv.slice(2).length) {
program.outputHelp();
util.shutdown();
}