diff options
Diffstat (limited to 'sinksh/syntax_modules')
-rw-r--r-- | sinksh/syntax_modules/sink_sync.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/sinksh/syntax_modules/sink_sync.cpp b/sinksh/syntax_modules/sink_sync.cpp index ef84734..2800af1 100644 --- a/sinksh/syntax_modules/sink_sync.cpp +++ b/sinksh/syntax_modules/sink_sync.cpp | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "common/log.h" | 28 | #include "common/log.h" |
29 | #include "common/storage.h" | 29 | #include "common/storage.h" |
30 | #include "common/definitions.h" | 30 | #include "common/definitions.h" |
31 | #include "common/secretstore.h" | ||
31 | 32 | ||
32 | #include "sinksh_utils.h" | 33 | #include "sinksh_utils.h" |
33 | #include "state.h" | 34 | #include "state.h" |
@@ -38,16 +39,30 @@ namespace SinkSync | |||
38 | 39 | ||
39 | bool sync(const QStringList &args, State &state) | 40 | bool sync(const QStringList &args, State &state) |
40 | { | 41 | { |
42 | auto options = SyntaxTree::parseOptions(args); | ||
43 | if (options.options.value("password").isEmpty()) { | ||
44 | state.printError(QObject::tr("Pass in a password with --password")); | ||
45 | return false; | ||
46 | } | ||
47 | auto password = options.options.value("password").first(); | ||
48 | |||
41 | Sink::Query query; | 49 | Sink::Query query; |
42 | 50 | if (!options.positionalArguments.isEmpty() && !SinkshUtils::isValidStoreType(options.positionalArguments.first())) { | |
43 | if (!args.isEmpty() && !SinkshUtils::isValidStoreType(args.first())) { | 51 | //We have only specified a resource |
44 | query.resourceFilter(args.first().toLatin1()); | 52 | query.resourceFilter(options.positionalArguments.first().toLatin1()); |
45 | } else { | 53 | } else { |
46 | if (!SinkshUtils::applyFilter(query, args)) { | 54 | //We have specified a full filter |
47 | state.printError(QObject::tr("Options: $type $resource/$folder/$subfolder")); | 55 | if (!SinkshUtils::applyFilter(query, options.positionalArguments)) { |
56 | state.printError(QObject::tr("Options: $type $resource/$folder/$subfolder --password $password")); | ||
48 | return false; | 57 | return false; |
49 | } | 58 | } |
50 | } | 59 | } |
60 | if (query.getResourceFilter().ids.isEmpty()) { | ||
61 | state.printError(QObject::tr("Failed to find resource filter")); | ||
62 | return false; | ||
63 | } | ||
64 | auto resourceId = query.getResourceFilter().ids.first(); | ||
65 | Sink::SecretStore::instance().insert(resourceId, password); | ||
51 | 66 | ||
52 | Sink::Store::synchronize(query) | 67 | Sink::Store::synchronize(query) |
53 | .then(Sink::ResourceControl::flushMessageQueue(query.getResourceFilter().ids)) | 68 | .then(Sink::ResourceControl::flushMessageQueue(query.getResourceFilter().ids)) |
@@ -65,7 +80,7 @@ bool sync(const QStringList &args, State &state) | |||
65 | 80 | ||
66 | Syntax::List syntax() | 81 | Syntax::List syntax() |
67 | { | 82 | { |
68 | Syntax sync("sync", QObject::tr("Syncronizes all resources that are listed; and empty list triggers a syncronizaton on all resources"), &SinkSync::sync, Syntax::EventDriven); | 83 | Syntax sync("sync", QObject::tr("Synchronizes a resource."), &SinkSync::sync, Syntax::EventDriven); |
69 | sync.completer = &SinkshUtils::resourceCompleter; | 84 | sync.completer = &SinkshUtils::resourceCompleter; |
70 | 85 | ||
71 | return Syntax::List() << sync; | 86 | return Syntax::List() << sync; |