mirror of
https://github.com/laurent22/joplin.git
synced 2026-06-06 20:10:22 +00:00
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com> Co-authored-by: Laurent Cozic <laurent22@users.noreply.github.com>
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import BaseCommand from './base-command';
|
|
import { _ } from '@joplin/lib/locale';
|
|
import BaseModel from '@joplin/lib/BaseModel';
|
|
import Folder from '@joplin/lib/models/Folder';
|
|
import uuid from '@joplin/lib/uuid';
|
|
|
|
class Command extends BaseCommand {
|
|
public override usage() {
|
|
return 'search <pattern> [notebook]';
|
|
}
|
|
|
|
public override description() {
|
|
return _('Searches for the given <pattern> in all the notes.');
|
|
}
|
|
|
|
public override compatibleUis() {
|
|
return ['gui'];
|
|
}
|
|
|
|
// eslint-disable-next-line id-denylist -- `notebook` is the CLI argument name declared in usage() and accessed via bracket notation; the identifier appears here only as a type property key
|
|
public override async action(args: { pattern: string; notebook?: string }) {
|
|
const pattern = args['pattern'];
|
|
const folderTitle = args['notebook'];
|
|
|
|
let folder = null;
|
|
if (folderTitle) {
|
|
folder = await Folder.loadByTitle(folderTitle);
|
|
if (!folder) throw new Error(_('Cannot find "%s".', folderTitle));
|
|
}
|
|
|
|
const searchId = uuid.create();
|
|
|
|
this.dispatch({
|
|
type: 'SEARCH_ADD',
|
|
search: {
|
|
id: searchId,
|
|
title: pattern,
|
|
query_pattern: pattern,
|
|
query_folder_id: folder ? folder.id : '',
|
|
type_: BaseModel.TYPE_SEARCH,
|
|
},
|
|
});
|
|
|
|
this.dispatch({
|
|
type: 'SEARCH_SELECT',
|
|
id: searchId,
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = Command;
|