2017-11-03 00:09:34 +00:00
|
|
|
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');
|
2017-11-10 22:18:00 +00:00
|
|
|
const { shim } = require('lib/shim.js');
|
2017-10-19 23:02:13 +01:00
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
|
|
|
class Command extends BaseCommand {
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
return 'attach <note> <file>';
|
|
|
|
}
|
|
|
|
|
|
|
|
description() {
|
|
|
|
return _('Attaches the given file to the note.');
|
|
|
|
}
|
|
|
|
|
|
|
|
async action(args) {
|
|
|
|
let title = args['note'];
|
|
|
|
|
|
|
|
let note = await app().loadItem(BaseModel.TYPE_NOTE, title, { parent: app().currentFolder() });
|
2017-12-26 11:38:53 +01:00
|
|
|
this.encryptionCheck(note);
|
2017-10-19 23:02:13 +01:00
|
|
|
if (!note) throw new Error(_('Cannot find "%s".', title));
|
|
|
|
|
|
|
|
const localFilePath = args['file'];
|
|
|
|
|
2017-11-10 22:18:00 +00:00
|
|
|
await shim.attachFileToNote(note, localFilePath);
|
2017-10-19 23:02:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Command;
|