Changeset View
Changeset View
Standalone View
Standalone View
sinksh/syntax_modules/sink_inspect.cpp
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 49 | if (Key::isValidInternal(bytes)) { | |||
---|---|---|---|---|---|
50 | return Key::fromInternalByteArray(bytes).toDisplayString(); | 50 | return Key::fromInternalByteArray(bytes).toDisplayString(); | ||
51 | } else if (Identifier::isValidInternal(bytes)) { | 51 | } else if (Identifier::isValidInternal(bytes)) { | ||
52 | return Identifier::fromInternalByteArray(bytes).toDisplayString(); | 52 | return Identifier::fromInternalByteArray(bytes).toDisplayString(); | ||
53 | } else { | 53 | } else { | ||
54 | return QString::fromUtf8(bytes); | 54 | return QString::fromUtf8(bytes); | ||
55 | } | 55 | } | ||
56 | } | 56 | } | ||
57 | 57 | | |||
58 | Syntax::List syntax(); | ||||
59 | | ||||
58 | bool inspect(const QStringList &args, State &state) | 60 | bool inspect(const QStringList &args, State &state) | ||
59 | { | 61 | { | ||
60 | if (args.isEmpty()) { | 62 | if (args.isEmpty()) { | ||
61 | state.printError(QObject::tr("Options: [--resource $resource] ([--db $db] [--filter $id] [--showinternal] | [--validaterids $type] | [--fulltext [$id]])")); | 63 | //state.printError(QObject::tr("Options: [--resource $resource] ([--db $db] [--filter $id] [--showinternal] | [--validaterids $type] | [--fulltext [$id]])")); | ||
64 | state.printError(syntax()[0].usage()); | ||||
65 | return false; | ||||
62 | } | 66 | } | ||
63 | auto options = SyntaxTree::parseOptions(args); | 67 | auto options = SyntaxTree::parseOptions(args); | ||
64 | auto resource = SinkshUtils::parseUid(options.options.value("resource").value(0).toUtf8()); | 68 | auto resource = SinkshUtils::parseUid(options.options.value("resource").value(0).toUtf8()); | ||
65 | 69 | | |||
66 | Sink::Storage::DataStore storage(Sink::storageLocation(), resource, Sink::Storage::DataStore::ReadOnly); | 70 | Sink::Storage::DataStore storage(Sink::storageLocation(), resource, Sink::Storage::DataStore::ReadOnly); | ||
67 | auto transaction = storage.createTransaction(Sink::Storage::DataStore::ReadOnly); | 71 | auto transaction = storage.createTransaction(Sink::Storage::DataStore::ReadOnly); | ||
68 | 72 | | |||
69 | if (options.options.contains("validaterids")) { | 73 | if (options.options.contains("validaterids")) { | ||
▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Line(s) | 195 | } else { | |||
231 | state.printLine("Keys take up " + QString::number(keySizeTotal) + " bytes => " + QString::number(keySizeTotal/1024) + " kb"); | 235 | state.printLine("Keys take up " + QString::number(keySizeTotal) + " bytes => " + QString::number(keySizeTotal/1024) + " kb"); | ||
232 | state.printLine("Values take up " + QString::number(valueSizeTotal) + " bytes => " + QString::number(valueSizeTotal/1024) + " kb"); | 236 | state.printLine("Values take up " + QString::number(valueSizeTotal) + " bytes => " + QString::number(valueSizeTotal/1024) + " kb"); | ||
233 | } | 237 | } | ||
234 | return false; | 238 | return false; | ||
235 | } | 239 | } | ||
236 | 240 | | |||
237 | Syntax::List syntax() | 241 | Syntax::List syntax() | ||
238 | { | 242 | { | ||
239 | Syntax state("inspect", QObject::tr("Inspect database for the resource requested"), &SinkInspect::inspect, Syntax::NotInteractive); | 243 | Syntax state("inspect", QObject::tr("Inspect database for the resource requested"), | ||
244 | &SinkInspect::inspect, Syntax::NotInteractive); | ||||
245 | | ||||
246 | state.addParameter("resource", | ||||
247 | { .name = "resource", .help = "Which resource to inspect", .required = true }); | ||||
248 | state.addParameter("db", | ||||
249 | { .name = "database", .help = "Which database to inspect"}); | ||||
250 | state.addParameter("filter", | ||||
251 | { .name = "id", .help = "A specific id to filter the results by (currently not working)"}); | ||||
252 | state.addFlag("showinternal", "Show internal fields only"); | ||||
253 | state.addParameter("validaterids", | ||||
254 | { .name = "type", .help = "Validate remote Ids of the given type"}); | ||||
255 | state.addParameter("fulltext", | ||||
256 | { .name = "id", .help = "If 'id' is not given, count the number of fulltext documents. Else, print the terms of the document with the given id"}); | ||||
257 | | ||||
240 | state.completer = &SinkshUtils::resourceCompleter; | 258 | state.completer = &SinkshUtils::resourceCompleter; | ||
241 | 259 | | |||
242 | return Syntax::List() << state; | 260 | return Syntax::List() << state; | ||
243 | } | 261 | } | ||
244 | 262 | | |||
245 | REGISTER_SYNTAX(SinkInspect) | 263 | REGISTER_SYNTAX(SinkInspect) | ||
246 | 264 | | |||
247 | } | 265 | } |