@bader-nasser/pdftools
Version:
PDF tools to manipulate and process PDF files
47 lines (46 loc) • 1.22 kB
JavaScript
// credit:
// https://oclif.io/docs/global_flags
import path from 'node:path';
import fs from 'fs-extra';
import { Command, Flags } from '@oclif/core';
import { execa } from 'execa';
export class BaseCommand extends Command {
static baseFlags = {
'dry-run': Flags.boolean({
char: 'D',
description: 'Pretend to work!',
aliases: ['dryRun'],
}),
silent: Flags.boolean({
char: 's',
description: 'Work silently unless there is an error!',
}),
};
async execute(command, args, dryRun) {
if (!dryRun) {
try {
await execa(command, args);
}
catch (error) {
const error_ = error;
console.error(error_.stderr);
this.exit(1);
}
}
}
async ensureDirExists(filePath) {
try {
const outputDirname = path.dirname(filePath);
await fs.ensureDir(outputDirname);
}
catch (error) {
console.error(error);
this.exit(1);
}
}
logger(message, silent) {
if (!silent) {
this.log(message);
}
}
}