joplin/CliClient/app/command-sync.js

62 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-07-10 20:03:46 +00:00
import { BaseCommand } from './base-command.js';
import { app } from './app.js';
import { _ } from 'lib/locale.js';
import { Setting } from 'lib/models/setting.js';
import { BaseItem } from 'lib/models/base-item.js';
import { vorpalUtils } from './vorpal-utils.js';
class Command extends BaseCommand {
usage() {
return 'sync';
}
description() {
return 'Synchronizes with remote storage.';
}
options() {
return [
['--random-failures', 'For debugging purposes. Do not use.'],
];
}
async action(args) {
2017-07-14 19:06:01 +00:00
let sync = await app().synchronizer(Setting.value('sync.target'));
2017-07-13 18:09:47 +00:00
let options = {
onProgress: (report) => {
2017-07-14 19:06:01 +00:00
let lines = sync.reportToLines(report);
if (lines.length) vorpalUtils.redraw(lines.join(' '));
2017-07-13 18:09:47 +00:00
},
onMessage: (msg) => {
vorpalUtils.redrawDone();
this.log(msg);
},
randomFailures: args.options['random-failures'] === true,
};
this.log(_('Synchronization target: %s', Setting.value('sync.target')));
2017-07-10 20:03:46 +00:00
2017-07-13 18:09:47 +00:00
if (!sync) throw new Error(_('Cannot initialize synchronizer.'));
2017-07-10 20:03:46 +00:00
2017-07-13 18:09:47 +00:00
this.log(_('Starting synchronization...'));
2017-07-10 20:03:46 +00:00
2017-07-13 18:09:47 +00:00
await sync.start(options);
vorpalUtils.redrawDone();
2017-07-15 22:47:11 +00:00
await app().refreshCurrentFolder();
2017-07-13 18:09:47 +00:00
this.log(_('Done.'));
2017-07-10 20:03:46 +00:00
}
async cancel() {
vorpalUtils.redrawDone();
this.log(_('Cancelling...'));
let sync = await app().synchronizer(Setting.value('sync.target'));
sync.cancel();
}
}
module.exports = Command;