zotero-categorise
Version:
A command-line tool to manage Zotero collections by placing items into specific collections based on their title, description, and tags.
75 lines (74 loc) • 3.92 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander");
const generate_1 = require("./generate");
const collection_1 = require("./collection");
const collectionByJson_1 = require("./collectionByJson");
const program = new commander_1.Command();
program.version('0.0.1');
program.option('-d, --debug', 'debug').option('--quiet', 'do not print output to command line');
function runner(fn, options) {
return __awaiter(this, void 0, void 0, function* () {
yield fn(options);
});
}
program
.command('help')
.description('Display help information.')
.action(() => {
program.help();
});
program
.command('collection')
.description('place an item into a collection after checking its title/description and tags')
.option('-c, --collection [collection...]', 'Collection Id to place item in')
.option('-i, --item [item...]', 'Item Id to place in collection')
.option('--itemsfromcollection <collection>', 'Process items in the provided collection')
.option('--itemswithtag <tag>', 'Process items with this tag')
.option('--itemswithouttag <tag>', 'Process items that do not have this tag')
.option('--itemsfromlibrary', 'Process all items in the library')
.option('-g, --group <group>', 'Group Id to place item in')
.option('-t, --test', 'test mode, do not actually place item in collection')
.option('--ignoretag [ignoretag...]', 'Ignore Items with the Zotero tag')
.option('--addtag [addtag...]', 'Add a tag to the item')
.option('-r, --recursive', 'Recursively add subcollections to the list')
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
runner(collection_1.collection, options);
}));
program
.command('generate ')
.description('create a JSON file that maps keywords to collections')
.option('-g --group [group]', 'Zotero group ID')
.option('-c --collection [collection...]', 'Zotero collection ID')
.option('-n --name [name]', 'Name of the json file', 'list.json')
.option('-r --recursive', 'Recursively add subcollections to the list')
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
runner(generate_1.generate, options);
}));
program
.command('collectionByJson')
.description('categorize items from a JSON file into Zotero collections.')
.option('-j, --json <json>', 'json file')
.option('-i, --item [item...]', 'Item Id to place in collection')
.option('--itemsfromcollection <collection>', 'Process items in the provided collection')
.option('--itemswithtag <tag>', 'Process items with this tag')
.option('--itemswithouttag <tag>', 'Process items that do not have this tag')
.option('--itemsfromlibrary', 'Process all items in the library')
.option('-t, --test', 'test mode, do not actually place item in collection')
.option('--ignoretag [ignoretag...]', 'Ignore Items with the Zotero tags')
.option('--addtag [addtag...]', 'Add a tags to the item')
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
runner(collectionByJson_1.generateByJSon, options);
}));
program.parse(process.argv);
module.exports = program;