summaryrefslogtreecommitdiffstats
path: root/sinksh/syntax_modules/sink_inspect.cpp
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2018-08-02 10:40:35 +0200
committerMinijackson <minijackson@riseup.net>2018-08-02 10:40:35 +0200
commiteb4c557efa38673eba773bda6b71a286d0c3c3b1 (patch)
tree570600682e6a21f6f5edefab880ef20f4f298e18 /sinksh/syntax_modules/sink_inspect.cpp
parenta24bf3db83d81d7d7677a1f0f750f208d32998a8 (diff)
downloadsink-eb4c557efa38673eba773bda6b71a286d0c3c3b1.tar.gz
sink-eb4c557efa38673eba773bda6b71a286d0c3c3b1.zip
Add subcommand/parameter/option/flag and automatic help
Diffstat (limited to 'sinksh/syntax_modules/sink_inspect.cpp')
-rw-r--r--sinksh/syntax_modules/sink_inspect.cpp40
1 files changed, 29 insertions, 11 deletions
diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp
index f9cc50a..d952a9b 100644
--- a/sinksh/syntax_modules/sink_inspect.cpp
+++ b/sinksh/syntax_modules/sink_inspect.cpp
@@ -55,10 +55,38 @@ QString parse(const QByteArray &bytes)
55 } 55 }
56} 56}
57 57
58bool inspect(const QStringList &args, State &state);
59
60Syntax::List syntax()
61{
62 Syntax state("inspect", QObject::tr("Inspect database for the resource requested"),
63 &SinkInspect::inspect, Syntax::NotInteractive);
64
65 state.addParameter("resource",
66 { .name = "resource", .help = "Which resource to inspect", .required = true });
67 state.addParameter("db",
68 { .name = "database", .help = "Which database to inspect"});
69 state.addParameter("filter",
70 { .name = "id", .help = "A specific id to filter the results by (currently not working)"});
71 state.addFlag("showinternal", "Show internal fields only");
72 state.addParameter("validaterids",
73 { .name = "type", .help = "Validate remote Ids of the given type"});
74 state.addParameter("fulltext",
75 { .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"});
76
77 state.completer = &SinkshUtils::resourceCompleter;
78
79 return Syntax::List() << state;
80}
81
82REGISTER_SYNTAX(SinkInspect)
83
58bool inspect(const QStringList &args, State &state) 84bool inspect(const QStringList &args, State &state)
59{ 85{
60 if (args.isEmpty()) { 86 if (args.isEmpty()) {
61 state.printError(QObject::tr("Options: [--resource $resource] ([--db $db] [--filter $id] [--showinternal] | [--validaterids $type] | [--fulltext [$id]])")); 87 //state.printError(QObject::tr("Options: [--resource $resource] ([--db $db] [--filter $id] [--showinternal] | [--validaterids $type] | [--fulltext [$id]])"));
88 state.printError(syntax()[0].usage());
89 return false;
62 } 90 }
63 auto options = SyntaxTree::parseOptions(args); 91 auto options = SyntaxTree::parseOptions(args);
64 auto resource = SinkshUtils::parseUid(options.options.value("resource").value(0).toUtf8()); 92 auto resource = SinkshUtils::parseUid(options.options.value("resource").value(0).toUtf8());
@@ -234,14 +262,4 @@ bool inspect(const QStringList &args, State &state)
234 return false; 262 return false;
235} 263}
236 264
237Syntax::List syntax()
238{
239 Syntax state("inspect", QObject::tr("Inspect database for the resource requested"), &SinkInspect::inspect, Syntax::NotInteractive);
240 state.completer = &SinkshUtils::resourceCompleter;
241
242 return Syntax::List() << state;
243}
244
245REGISTER_SYNTAX(SinkInspect)
246
247} 265}