1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-04-01 21:24:45 +02:00

Cli: Add support for "batch" command

This commit is contained in:
Laurent Cozic 2021-05-01 16:09:59 +02:00
parent 4be5182913
commit eef86d6166
2 changed files with 39 additions and 1 deletions

View File

@ -9,6 +9,7 @@ const Tag = require('@joplin/lib/models/Tag').default;
const Setting = require('@joplin/lib/models/Setting').default;
const { reg } = require('@joplin/lib/registry.js');
const { fileExtension } = require('@joplin/lib/path-utils');
const { splitCommandString } = require('@joplin/lib/string-utils');
const { _ } = require('@joplin/lib/locale');
const fs = require('fs-extra');
const { cliUtils } = require('./cli-utils.js');
@ -386,6 +387,21 @@ class Application extends BaseApplication {
return output;
}
async commandList(argv) {
if (argv.length && argv[0] === 'batch') {
const commands = [];
const commandLines = (await fs.readFile(argv[1], 'utf-8')).split('\n');
for (const commandLine of commandLines) {
if (!commandLine.trim()) continue;
const splitted = splitCommandString(commandLine.trim());
commands.push(splitted);
}
return commands;
} else {
return [argv];
}
}
async start(argv) {
argv = await super.start(argv);
@ -403,7 +419,10 @@ class Application extends BaseApplication {
await this.applySettingsSideEffects();
try {
await this.execCommand(argv);
const commands = await this.commandList(argv);
for (const command of commands) {
await this.execCommand(command);
}
} catch (error) {
if (this.showStackTraces_) {
console.error(error);

View File

@ -0,0 +1,19 @@
const { BaseCommand } = require('./base-command.js');
const { _ } = require('@joplin/lib/locale');
class Command extends BaseCommand {
usage() {
return 'batch <file-path>';
}
description() {
return _('Runs the commands contained in the text file. There should be one command per line.');
}
async action() {
// Implementation is in app.js::commandList()
throw new Error('No implemented');
}
}
module.exports = Command;