* Start work on new oputil format: oputil <command> <action> <args> <target>

* Add auto tagging for oputil scan
This commit is contained in:
Bryan Ashby 2017-02-13 22:51:20 -07:00
parent aa40d998b2
commit 9b0f956934
2 changed files with 70 additions and 25 deletions

View File

@ -584,10 +584,14 @@ function scanFile(filePath, options, iterator, cb) {
);
}
function scanFileAreaForChanges(areaInfo, iterator, cb) {
if(!cb && _.isFunction(iterator)) {
function scanFileAreaForChanges(areaInfo, options, iterator, cb) {
if(3 === arguments.length && _.isFunction(iterator)) {
cb = iterator;
iterator = null;
} else if(2 === arguments.length && _.isFunction(options)) {
cb = options;
iterator = null;
options = {};
}
const storageLocations = getAreaStorageLocations(areaInfo);
@ -632,6 +636,11 @@ function scanFileAreaForChanges(areaInfo, iterator, cb) {
if(dupeEntries.length > 0) {
// :TODO: Handle duplidates -- what to do here???
} else {
if(Array.isArray(options.tags)) {
options.tags.forEach(tag => {
fileEntry.hashTags.add(tag);
});
}
addNewFileEntry(fileEntry, fullPath, err => {
// pass along error; we failed to insert a record in our DB or something else bad
return nextFile(err);

View File

@ -35,10 +35,11 @@ const USAGE_HELP = {
global args:
--config PATH : specify config path (${getDefaultConfigPath()})
commands:
where <command> is one of:
user : user utilities
config : config file management
file-base : file base management
file-base
fb : file base management
`,
User :
@ -59,10 +60,14 @@ valid args:
--new : generate a new/initial configuration
`,
FileBase :
`usage: oputil.js file-base <args>
`usage: oputil.js file-base <action> [<args>] [<action_specific>]
valid args:
--scan AREA_TAG : (re)scan area specified by AREA_TAG for new files
where <action> is one of:
scan AREA_TAG : (re)scan area specified by AREA_TAG for new files
multiple area tags can be specified in form of AREA_TAG1 AREA_TAG2 ...
scan args:
--tags TAG1,TAG2,... : specify tag(s) to assign to discovered entries
`
};
@ -438,7 +443,41 @@ function handleConfigCommand() {
}
}
function scanFileBaseArea(areaTag, options, iterator, cb) {
async.waterfall(
[
function getFileArea(callback) {
const fileAreaMod = require('./core/file_base_area.js');
const areaInfo = fileAreaMod.getFileAreaByTag(areaTag);
if(!areaInfo) {
return callback(new Error(`Invalid file base area tag: ${areaTag}`));
}
return callback(null, fileAreaMod, areaInfo);
},
function performScan(fileAreaMod, areaInfo, callback) {
fileAreaMod.scanFileAreaForChanges(areaInfo, options, iterator, err => {
return callback(err);
});
}
],
err => {
return cb(err);
}
);
}
function fileAreaScan() {
const options = {};
const tags = argv.tags;
if(tags) {
options.tags = tags.split(',');
}
const areaTags = argv._.slice(2);
function scanFileIterator(stepInfo, nextScanStep) {
if('start' === stepInfo.step) {
console.info(`Scanning ${stepInfo.filePath}...`);
@ -447,23 +486,17 @@ function fileAreaScan() {
// :TODO: add 'finished' step when avail
}
async.waterfall(
async.series(
[
function init(callback) {
return initConfigAndDatabases(callback);
},
function getFileArea(callback) {
const fileAreaMod = require('./core/file_base_area.js');
const areaInfo = fileAreaMod.getFileAreaByTag(argv.scan);
if(!areaInfo) {
return callback(new Error('Invalid file area'));
}
return callback(null, fileAreaMod, areaInfo);
},
function performScan(fileAreaMod, areaInfo, callback) {
fileAreaMod.scanFileAreaForChanges(areaInfo, scanFileIterator, err => {
function scanAreas(callback) {
async.eachSeries(areaTags, (areaTag, nextAreaTag) => {
scanFileBaseArea(areaTag, options, scanFileIterator, err => {
return nextAreaTag(err);
});
}, err => {
return callback(err);
});
}
@ -482,8 +515,10 @@ function handleFileBaseCommand() {
return printUsageAndSetExitCode('FileBase', ExitCodes.ERROR);
}
if(argv.scan) {
return fileAreaScan(argv.scan);
const action = argv._[1];
switch(action) {
case 'scan' : return fileAreaScan();
}
}
@ -511,6 +546,7 @@ function main() {
break;
case 'file-base' :
case 'fb' :
handleFileBaseCommand();
break;