diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-25 11:02:59 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-25 11:02:59 +0100 |
commit | 50df30dfea10a3c1ee6fe8de9856fdb4596a08fe (patch) | |
tree | c5750b09e000f82e1dc7c8278e575aa3effeab0b /sinksh | |
parent | 684e3dfd401282674a2d28b7109f4f4abb83b62c (diff) | |
download | sink-50df30dfea10a3c1ee6fe8de9856fdb4596a08fe.tar.gz sink-50df30dfea10a3c1ee6fe8de9856fdb4596a08fe.zip |
Share the filter syntax for count and list
Diffstat (limited to 'sinksh')
-rw-r--r-- | sinksh/sinksh_utils.cpp | 21 | ||||
-rw-r--r-- | sinksh/syntax_modules/sink_count.cpp | 2 | ||||
-rw-r--r-- | sinksh/syntax_modules/sink_list.cpp | 25 |
3 files changed, 24 insertions, 24 deletions
diff --git a/sinksh/sinksh_utils.cpp b/sinksh/sinksh_utils.cpp index 3a3484a..3fc9c29 100644 --- a/sinksh/sinksh_utils.cpp +++ b/sinksh/sinksh_utils.cpp | |||
@@ -22,6 +22,7 @@ | |||
22 | 22 | ||
23 | #include "common/store.h" | 23 | #include "common/store.h" |
24 | #include "common/log.h" | 24 | #include "common/log.h" |
25 | #include "common/propertyparser.h" | ||
25 | 26 | ||
26 | #include "utils.h" | 27 | #include "utils.h" |
27 | 28 | ||
@@ -195,7 +196,25 @@ bool applyFilter(Sink::Query &query, const QStringList &args_) | |||
195 | 196 | ||
196 | bool applyFilter(Sink::Query &query, const SyntaxTree::Options &options) | 197 | bool applyFilter(Sink::Query &query, const SyntaxTree::Options &options) |
197 | { | 198 | { |
198 | return applyFilter(query, options.positionalArguments); | 199 | bool ret = applyFilter(query, options.positionalArguments); |
200 | if (options.options.contains("resource")) { | ||
201 | for (const auto &f : options.options.value("resource")) { | ||
202 | query.resourceFilter(f.toLatin1()); | ||
203 | } | ||
204 | } | ||
205 | if (options.options.contains("filter")) { | ||
206 | for (const auto &f : options.options.value("filter")) { | ||
207 | auto filter = f.split("="); | ||
208 | const auto property = filter.value(0).toLatin1(); | ||
209 | query.filter(property, Sink::PropertyParser::parse(query.type(), property, filter.value(1))); | ||
210 | } | ||
211 | } | ||
212 | if (options.options.contains("id")) { | ||
213 | for (const auto &f : options.options.value("id")) { | ||
214 | query.filter(f.toUtf8()); | ||
215 | } | ||
216 | } | ||
217 | return ret; | ||
199 | } | 218 | } |
200 | 219 | ||
201 | } | 220 | } |
diff --git a/sinksh/syntax_modules/sink_count.cpp b/sinksh/syntax_modules/sink_count.cpp index 9b6aa1e..04a9550 100644 --- a/sinksh/syntax_modules/sink_count.cpp +++ b/sinksh/syntax_modules/sink_count.cpp | |||
@@ -41,7 +41,7 @@ bool count(const QStringList &args, State &state) | |||
41 | { | 41 | { |
42 | Sink::Query query; | 42 | Sink::Query query; |
43 | query.setId("count"); | 43 | query.setId("count"); |
44 | if (!SinkshUtils::applyFilter(query, args)) { | 44 | if (!SinkshUtils::applyFilter(query, SyntaxTree::parseOptions(args))) { |
45 | state.printError(QObject::tr("Options: $type $filter")); | 45 | state.printError(QObject::tr("Options: $type $filter")); |
46 | return false; | 46 | return false; |
47 | } | 47 | } |
diff --git a/sinksh/syntax_modules/sink_list.cpp b/sinksh/syntax_modules/sink_list.cpp index e4c4837..b002438 100644 --- a/sinksh/syntax_modules/sink_list.cpp +++ b/sinksh/syntax_modules/sink_list.cpp | |||
@@ -96,9 +96,6 @@ bool list(const QStringList &args_, State &state) | |||
96 | } | 96 | } |
97 | 97 | ||
98 | auto options = SyntaxTree::parseOptions(args_); | 98 | auto options = SyntaxTree::parseOptions(args_); |
99 | |||
100 | auto type = options.positionalArguments.isEmpty() ? QString{} : options.positionalArguments.first(); | ||
101 | |||
102 | bool asLine = true; | 99 | bool asLine = true; |
103 | 100 | ||
104 | Sink::Query query; | 101 | Sink::Query query; |
@@ -107,30 +104,14 @@ bool list(const QStringList &args_, State &state) | |||
107 | state.printError(QObject::tr("Options: $type [--resource $resource] [--compact] [--filter $property=$value] [--showall|--show $property]")); | 104 | state.printError(QObject::tr("Options: $type [--resource $resource] [--compact] [--filter $property=$value] [--showall|--show $property]")); |
108 | return false; | 105 | return false; |
109 | } | 106 | } |
110 | if (options.options.contains("resource")) { | 107 | |
111 | for (const auto &f : options.options.value("resource")) { | ||
112 | query.resourceFilter(f.toLatin1()); | ||
113 | } | ||
114 | } | ||
115 | if (options.options.contains("filter")) { | ||
116 | for (const auto &f : options.options.value("filter")) { | ||
117 | auto filter = f.split("="); | ||
118 | const auto property = filter.value(0).toLatin1(); | ||
119 | query.filter(property, Sink::PropertyParser::parse(type.toLatin1(), property, filter.value(1))); | ||
120 | } | ||
121 | } | ||
122 | if (options.options.contains("id")) { | ||
123 | for (const auto &f : options.options.value("id")) { | ||
124 | query.filter(f.toUtf8()); | ||
125 | } | ||
126 | } | ||
127 | auto compact = options.options.contains("compact"); | 108 | auto compact = options.options.contains("compact"); |
128 | if (!options.options.contains("showall")) { | 109 | if (!options.options.contains("showall")) { |
129 | if (options.options.contains("show")) { | 110 | if (options.options.contains("show")) { |
130 | auto list = options.options.value("show"); | 111 | auto list = options.options.value("show"); |
131 | std::transform(list.constBegin(), list.constEnd(), std::back_inserter(query.requestedProperties), [] (const QString &s) { return s.toLatin1(); }); | 112 | std::transform(list.constBegin(), list.constEnd(), std::back_inserter(query.requestedProperties), [] (const QString &s) { return s.toLatin1(); }); |
132 | } else { | 113 | } else { |
133 | query.requestedProperties = SinkshUtils::requestedProperties(type); | 114 | query.requestedProperties = SinkshUtils::requestedProperties(query.type()); |
134 | } | 115 | } |
135 | } else { | 116 | } else { |
136 | asLine = false; | 117 | asLine = false; |
@@ -139,7 +120,7 @@ bool list(const QStringList &args_, State &state) | |||
139 | QByteArrayList toPrint; | 120 | QByteArrayList toPrint; |
140 | QStringList tableLine; | 121 | QStringList tableLine; |
141 | 122 | ||
142 | for (const auto &o : SinkshUtils::getStore(type).read(query)) { | 123 | for (const auto &o : SinkshUtils::getStore(query.type()).read(query)) { |
143 | if (tableLine.isEmpty()) { | 124 | if (tableLine.isEmpty()) { |
144 | tableLine << QObject::tr("Resource") << QObject::tr("Identifier"); | 125 | tableLine << QObject::tr("Resource") << QObject::tr("Identifier"); |
145 | if (query.requestedProperties.isEmpty()) { | 126 | if (query.requestedProperties.isEmpty()) { |