* Start work on new oputil format: oputil <command> <action> <args> <target>
* Add auto tagging for oputil scan
This commit is contained in:
parent
aa40d998b2
commit
9b0f956934
|
@ -584,10 +584,14 @@ function scanFile(filePath, options, iterator, cb) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function scanFileAreaForChanges(areaInfo, iterator, cb) {
|
function scanFileAreaForChanges(areaInfo, options, iterator, cb) {
|
||||||
if(!cb && _.isFunction(iterator)) {
|
if(3 === arguments.length && _.isFunction(iterator)) {
|
||||||
cb = iterator;
|
cb = iterator;
|
||||||
iterator = null;
|
iterator = null;
|
||||||
|
} else if(2 === arguments.length && _.isFunction(options)) {
|
||||||
|
cb = options;
|
||||||
|
iterator = null;
|
||||||
|
options = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const storageLocations = getAreaStorageLocations(areaInfo);
|
const storageLocations = getAreaStorageLocations(areaInfo);
|
||||||
|
@ -632,6 +636,11 @@ function scanFileAreaForChanges(areaInfo, iterator, cb) {
|
||||||
if(dupeEntries.length > 0) {
|
if(dupeEntries.length > 0) {
|
||||||
// :TODO: Handle duplidates -- what to do here???
|
// :TODO: Handle duplidates -- what to do here???
|
||||||
} else {
|
} else {
|
||||||
|
if(Array.isArray(options.tags)) {
|
||||||
|
options.tags.forEach(tag => {
|
||||||
|
fileEntry.hashTags.add(tag);
|
||||||
|
});
|
||||||
|
}
|
||||||
addNewFileEntry(fileEntry, fullPath, err => {
|
addNewFileEntry(fileEntry, fullPath, err => {
|
||||||
// pass along error; we failed to insert a record in our DB or something else bad
|
// pass along error; we failed to insert a record in our DB or something else bad
|
||||||
return nextFile(err);
|
return nextFile(err);
|
||||||
|
|
76
oputil.js
76
oputil.js
|
@ -35,10 +35,11 @@ const USAGE_HELP = {
|
||||||
global args:
|
global args:
|
||||||
--config PATH : specify config path (${getDefaultConfigPath()})
|
--config PATH : specify config path (${getDefaultConfigPath()})
|
||||||
|
|
||||||
commands:
|
where <command> is one of:
|
||||||
user : user utilities
|
user : user utilities
|
||||||
config : config file management
|
config : config file management
|
||||||
file-base : file base management
|
file-base
|
||||||
|
fb : file base management
|
||||||
|
|
||||||
`,
|
`,
|
||||||
User :
|
User :
|
||||||
|
@ -59,10 +60,14 @@ valid args:
|
||||||
--new : generate a new/initial configuration
|
--new : generate a new/initial configuration
|
||||||
`,
|
`,
|
||||||
FileBase :
|
FileBase :
|
||||||
`usage: oputil.js file-base <args>
|
`usage: oputil.js file-base <action> [<args>] [<action_specific>]
|
||||||
|
|
||||||
valid args:
|
where <action> is one of:
|
||||||
--scan AREA_TAG : (re)scan area specified by AREA_TAG for new files
|
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() {
|
function fileAreaScan() {
|
||||||
|
const options = {};
|
||||||
|
|
||||||
|
const tags = argv.tags;
|
||||||
|
if(tags) {
|
||||||
|
options.tags = tags.split(',');
|
||||||
|
}
|
||||||
|
|
||||||
|
const areaTags = argv._.slice(2);
|
||||||
|
|
||||||
function scanFileIterator(stepInfo, nextScanStep) {
|
function scanFileIterator(stepInfo, nextScanStep) {
|
||||||
if('start' === stepInfo.step) {
|
if('start' === stepInfo.step) {
|
||||||
console.info(`Scanning ${stepInfo.filePath}...`);
|
console.info(`Scanning ${stepInfo.filePath}...`);
|
||||||
|
@ -447,23 +486,17 @@ function fileAreaScan() {
|
||||||
// :TODO: add 'finished' step when avail
|
// :TODO: add 'finished' step when avail
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall(
|
async.series(
|
||||||
[
|
[
|
||||||
function init(callback) {
|
function init(callback) {
|
||||||
return initConfigAndDatabases(callback);
|
return initConfigAndDatabases(callback);
|
||||||
},
|
},
|
||||||
function getFileArea(callback) {
|
function scanAreas(callback) {
|
||||||
const fileAreaMod = require('./core/file_base_area.js');
|
async.eachSeries(areaTags, (areaTag, nextAreaTag) => {
|
||||||
|
scanFileBaseArea(areaTag, options, scanFileIterator, err => {
|
||||||
const areaInfo = fileAreaMod.getFileAreaByTag(argv.scan);
|
return nextAreaTag(err);
|
||||||
if(!areaInfo) {
|
});
|
||||||
return callback(new Error('Invalid file area'));
|
}, err => {
|
||||||
}
|
|
||||||
|
|
||||||
return callback(null, fileAreaMod, areaInfo);
|
|
||||||
},
|
|
||||||
function performScan(fileAreaMod, areaInfo, callback) {
|
|
||||||
fileAreaMod.scanFileAreaForChanges(areaInfo, scanFileIterator, err => {
|
|
||||||
return callback(err);
|
return callback(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -482,8 +515,10 @@ function handleFileBaseCommand() {
|
||||||
return printUsageAndSetExitCode('FileBase', ExitCodes.ERROR);
|
return printUsageAndSetExitCode('FileBase', ExitCodes.ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(argv.scan) {
|
const action = argv._[1];
|
||||||
return fileAreaScan(argv.scan);
|
|
||||||
|
switch(action) {
|
||||||
|
case 'scan' : return fileAreaScan();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -511,6 +546,7 @@ function main() {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'file-base' :
|
case 'file-base' :
|
||||||
|
case 'fb' :
|
||||||
handleFileBaseCommand();
|
handleFileBaseCommand();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue