You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-10 00:05:42 +02:00
Cli: Add support for "batch" command
This commit is contained in:
@ -9,6 +9,7 @@ const Tag = require('@joplin/lib/models/Tag').default;
|
|||||||
const Setting = require('@joplin/lib/models/Setting').default;
|
const Setting = require('@joplin/lib/models/Setting').default;
|
||||||
const { reg } = require('@joplin/lib/registry.js');
|
const { reg } = require('@joplin/lib/registry.js');
|
||||||
const { fileExtension } = require('@joplin/lib/path-utils');
|
const { fileExtension } = require('@joplin/lib/path-utils');
|
||||||
|
const { splitCommandString } = require('@joplin/lib/string-utils');
|
||||||
const { _ } = require('@joplin/lib/locale');
|
const { _ } = require('@joplin/lib/locale');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const { cliUtils } = require('./cli-utils.js');
|
const { cliUtils } = require('./cli-utils.js');
|
||||||
@ -386,6 +387,21 @@ class Application extends BaseApplication {
|
|||||||
return output;
|
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) {
|
async start(argv) {
|
||||||
argv = await super.start(argv);
|
argv = await super.start(argv);
|
||||||
|
|
||||||
@ -403,7 +419,10 @@ class Application extends BaseApplication {
|
|||||||
await this.applySettingsSideEffects();
|
await this.applySettingsSideEffects();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.execCommand(argv);
|
const commands = await this.commandList(argv);
|
||||||
|
for (const command of commands) {
|
||||||
|
await this.execCommand(command);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (this.showStackTraces_) {
|
if (this.showStackTraces_) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
19
packages/app-cli/app/command-batch.js
Normal file
19
packages/app-cli/app/command-batch.js
Normal 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;
|
Reference in New Issue
Block a user