* Default upload descriptions based on file names if no FILE_ID.DIZ/etc. could be found

* Add default desc & prompt for desc to oputil fb scan
This commit is contained in:
Bryan Ashby
2017-02-24 23:39:31 -07:00
parent 9a2b48ac47
commit 97e19957ce
8 changed files with 67 additions and 13 deletions

View File

@@ -23,7 +23,14 @@ const exitCodes = exports.ExitCodes = {
BAD_ARGS : -3,
};
const argv = exports.argv = require('minimist')(process.argv.slice(2));
const argv = exports.argv = require('minimist')(process.argv.slice(2), {
alias : {
h : 'help',
v : 'version',
c : 'config',
n : 'no-prompt',
}
});
function printUsageAndSetExitCode(errMsg, exitCode) {
if(_.isUndefined(exitCode)) {

View File

@@ -9,12 +9,14 @@ const initConfigAndDatabases = require('./oputil_common.js').initConfigAndDataba
const getHelpFor = require('./oputil_help.js').getHelpFor;
const getAreaAndStorage = require('./oputil_common.js').getAreaAndStorage;
const Errors = require('../../core/enig_error.js').Errors;
const getDescFromFileName = require('../../core/file_base_area.js').getDescFromFileName;
const async = require('async');
const fs = require('fs');
const paths = require('path');
const _ = require('lodash');
const moment = require('moment');
const inq = require('inquirer');
exports.handleFileBaseCommand = handleFileBaseCommand;
@@ -33,6 +35,40 @@ exports.handleFileBaseCommand = handleFileBaseCommand;
let fileArea; // required during init
function finalizeEntryAndPersist(fileEntry, cb) {
async.series(
[
function getDescIfNeeded(callback) {
if(false === argv.prompt || ( fileEntry.desc && fileEntry.desc.length > 0 ) ) {
return callback(null);
}
const questions = [
{
name : 'desc',
message : `Description for ${fileEntry.fileName}:`,
type : 'input',
default : getDescFromFileName(fileEntry.fileName),
}
];
inq.prompt(questions).then( answers => {
fileEntry.desc = answers.desc;
return callback(null);
});
},
function persist(callback) {
fileEntry.persist( err => {
return callback(err);
});
}
],
err => {
return cb(err);
}
);
}
function scanFileAreaForChanges(areaInfo, options, cb) {
const storageLocations = fileArea.getAreaStorageLocations(areaInfo).filter(sl => {
@@ -94,7 +130,7 @@ function scanFileAreaForChanges(areaInfo, options, cb) {
});
}
fileEntry.persist( err => {
finalizeEntryAndPersist(fileEntry, err => {
return nextFile(err);
});
}

View File

@@ -12,13 +12,13 @@ const usageHelp = exports.USAGE_HELP = {
<command> [<args>]
global args:
--config PATH : specify config path (${getDefaultConfigPath()})
--no-prompt : assume defaults/don't prompt for input where possible
-c, --config PATH : specify config path (${getDefaultConfigPath()})
-n, --no-prompt : assume defaults/don't prompt for input where possible
where <command> is one of:
user : user utilities
config : config file management
fb : file base management
user : user utilities
config : config file management
fb : file base management
`,
User :

View File

@@ -22,7 +22,7 @@ module.exports = function() {
if(0 === argv._.length ||
'help' === argv._[0])
{
printUsageAndSetExitCode(getHelpFor('General'), ExitCodes.SUCCESS);
return printUsageAndSetExitCode(getHelpFor('General'), ExitCodes.SUCCESS);
}
switch(argv._[0]) {