* 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:
parent
9a2b48ac47
commit
97e19957ce
|
@ -32,6 +32,7 @@ exports.getFileEntryPath = getFileEntryPath;
|
|||
exports.changeFileAreaWithOptions = changeFileAreaWithOptions;
|
||||
exports.scanFile = scanFile;
|
||||
exports.scanFileAreaForChanges = scanFileAreaForChanges;
|
||||
exports.getDescFromFileName = getDescFromFileName;
|
||||
|
||||
const WellKnownAreaTags = exports.WellKnownAreaTags = {
|
||||
Invalid : '',
|
||||
|
@ -670,3 +671,11 @@ function scanFileAreaForChanges(areaInfo, options, iterator, cb) {
|
|||
return cb(err);
|
||||
});
|
||||
}
|
||||
|
||||
function getDescFromFileName(fileName) {
|
||||
// :TODO: this method could use some more logic to really be nice.
|
||||
const ext = paths.extname(fileName);
|
||||
const name = paths.basename(fileName, ext);
|
||||
|
||||
return _.upperFirst(name.replace(/[\-_.+]/g, ' ').replace(/\s+/g, ' '));
|
||||
}
|
|
@ -290,8 +290,9 @@ module.exports = class FileEntry {
|
|||
}
|
||||
}
|
||||
|
||||
// :TODO: Use static get accessor:
|
||||
static getWellKnownMetaValues() { return Object.keys(FILE_WELL_KNOWN_META); }
|
||||
static get WellKnownMetaValues() {
|
||||
return Object.keys(FILE_WELL_KNOWN_META);
|
||||
}
|
||||
|
||||
static findFileBySha(sha, cb) {
|
||||
// full or partial SHA-256
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ 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
|
||||
|
|
|
@ -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]) {
|
||||
|
|
|
@ -229,7 +229,7 @@ exports.getModule = class FileAreaList extends MenuModule {
|
|||
// We need the entry object to contain meta keys even if they are empty as
|
||||
// consumers may very likely attempt to use them
|
||||
//
|
||||
const metaValues = FileEntry.getWellKnownMetaValues();
|
||||
const metaValues = FileEntry.WellKnownMetaValues;
|
||||
metaValues.forEach(name => {
|
||||
const value = !_.isUndefined(currEntry.meta[name]) ? currEntry.meta[name] : 'N/A';
|
||||
entryInfo[_.camelCase(name)] = value;
|
||||
|
|
|
@ -8,6 +8,7 @@ const getSortedAvailableFileAreas = require('../core/file_base_area.js').getSor
|
|||
const getAreaDefaultStorageDirectory = require('../core/file_base_area.js').getAreaDefaultStorageDirectory;
|
||||
const scanFile = require('../core/file_base_area.js').scanFile;
|
||||
const getFileAreaByTag = require('../core/file_base_area.js').getFileAreaByTag;
|
||||
const getDescFromFileName = require('../core/file_base_area.js').getDescFromFileName;
|
||||
const ansiGoto = require('../core/ansi_term.js').goto;
|
||||
const moveFileWithCollisionHandling = require('../core/file_util.js').moveFileWithCollisionHandling;
|
||||
const pathWithTerminatingSeparator = require('../core/file_util.js').pathWithTerminatingSeparator;
|
||||
|
@ -681,7 +682,7 @@ exports.getModule = class UploadModule extends MenuModule {
|
|||
self.viewControllers.fileDetails.switchFocus(MciViewIds.fileDetails.tags);
|
||||
} else {
|
||||
descView.setPropertyValue('mode', 'edit');
|
||||
descView.setText('');
|
||||
descView.setText(getDescFromFileName(fileEntry.fileName)); // try to come up with something good as a default
|
||||
descView.acceptsFocus = true;
|
||||
self.viewControllers.fileDetails.switchFocus(MciViewIds.fileDetails.desc);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue