一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
46 行
1.6 KiB
TypeScript
46 行
1.6 KiB
TypeScript
import BaseCommand from './base-command';
|
|
import app from './app';
|
|
import { _ } from '@joplin/lib/locale';
|
|
import Folder from '@joplin/lib/models/Folder';
|
|
import { ModelType } from '@joplin/lib/BaseModel';
|
|
import { substrWithEllipsis } from '@joplin/lib/string-utils';
|
|
|
|
class Command extends BaseCommand {
|
|
public override usage() {
|
|
return 'rmbook <notebook>';
|
|
}
|
|
|
|
public override description() {
|
|
return _('Deletes the given notebook.');
|
|
}
|
|
|
|
public override options() {
|
|
return [
|
|
['-f, --force', _('Deletes the notebook without asking for confirmation.')],
|
|
['-p, --permanent', _('Permanently deletes the notebook, skipping the trash.')],
|
|
];
|
|
}
|
|
|
|
public override async action(args: { 'notebook': string; options?: { force?: boolean; permanent?: boolean } }) {
|
|
const pattern = args['notebook'];
|
|
const force = args.options && args.options.force === true;
|
|
|
|
const folder = await app().loadItemOrFail(ModelType.Folder, pattern);
|
|
|
|
const permanent = args.options?.permanent === true || !!folder.deleted_time;
|
|
const ellipsizedFolderTitle = substrWithEllipsis(folder.title, 0, 32);
|
|
let msg;
|
|
if (permanent) {
|
|
msg = _('Permanently delete notebook "%s"?\n\nAll notes and sub-notebooks within this notebook will be permanently deleted.', ellipsizedFolderTitle);
|
|
} else {
|
|
msg = _('Move notebook "%s" to the trash?\n\nAll notes and sub-notebooks within this notebook will also be moved to the trash.', ellipsizedFolderTitle);
|
|
}
|
|
const ok = force ? true : await this.prompt(msg, { booleanAnswerDefault: 'n' });
|
|
if (!ok) return;
|
|
|
|
await Folder.delete(folder.id, { toTrash: !permanent, sourceDescription: 'rmbook command' });
|
|
}
|
|
}
|
|
|
|
module.exports = Command;
|