1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-26 18:58:21 +02:00
joplin/CliClient/app/command-search.js

56 lines
1.2 KiB
JavaScript
Raw Normal View History

const { BaseCommand } = require('./base-command.js');
const { app } = require('./app.js');
const { _ } = require('lib/locale.js');
2017-12-14 18:12:14 +00:00
const BaseModel = require('lib/BaseModel.js');
const Folder = require('lib/models/Folder.js');
const Note = require('lib/models/Note.js');
const { sprintf } = require('sprintf-js');
const { time } = require('lib/time-utils.js');
const { uuid } = require('lib/uuid.js');
2017-07-17 19:56:14 +00:00
class Command extends BaseCommand {
usage() {
2017-07-28 18:13:07 +00:00
return 'search <pattern> [notebook]';
2017-07-17 19:56:14 +00:00
}
description() {
2017-07-18 18:21:03 +00:00
return _('Searches for the given <pattern> in all the notes.');
2017-07-17 19:56:14 +00:00
}
compatibleUis() {
return ['gui'];
}
2017-07-17 19:56:14 +00:00
async action(args) {
let pattern = args['pattern'];
let folderTitle = args['notebook'];
let folder = null;
if (folderTitle) {
folder = await Folder.loadByTitle(folderTitle);
2017-07-18 18:21:03 +00:00
if (!folder) throw new Error(_('Cannot find "%s".', folderTitle));
2017-07-17 19:56:14 +00:00
}
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,
},
2017-07-17 19:56:14 +00:00
});
this.dispatch({
type: 'SEARCH_SELECT',
id: searchId,
});
2017-07-17 19:56:14 +00:00
}
}
module.exports = Command;