From 1c455b9a0b6d5a7abb0e8e9ab68e338c62811d24 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 13 Aug 2017 14:58:34 -0600 Subject: sinksh show cleanup --- sinksh/syntax_modules/sink_show.cpp | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'sinksh/syntax_modules/sink_show.cpp') diff --git a/sinksh/syntax_modules/sink_show.cpp b/sinksh/syntax_modules/sink_show.cpp index 391505a..7a4166f 100644 --- a/sinksh/syntax_modules/sink_show.cpp +++ b/sinksh/syntax_modules/sink_show.cpp @@ -18,18 +18,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include #include #include // tr() #include #include -#include "common/resource.h" #include "common/storage.h" -#include "common/resourceconfig.h" -#include "common/log.h" -#include "common/storage.h" -#include "common/definitions.h" #include "sinksh_utils.h" #include "state.h" @@ -41,25 +35,24 @@ namespace SinkShow bool show(const QStringList &args, State &state) { if (args.isEmpty()) { - state.printError(QObject::tr("Please provide at least one type to show (e.g. resource, ..")); + state.printError(QObject::tr("Options: $type --resource $resource --id $id")); return false; } - auto argList = args; - if (argList.size() < 2 || !SinkshUtils::isValidStoreType(argList.at(0))) { + auto options = SyntaxTree::parseOptions(args); + + auto type = options.positionalArguments.isEmpty() ? QString{} : options.positionalArguments.first(); + auto resource = options.options.value("resource"); + auto id = options.options.value("id"); + + if (id.isEmpty() || resource.isEmpty() || !SinkshUtils::isValidStoreType(type)) { state.printError(QObject::tr("Invalid command syntax. Supply type and resource at least.")); return false; } - auto type = argList.takeFirst(); - auto resource = argList.takeFirst(); - bool queryForResourceOrAgent = argList.isEmpty(); Sink::Query query; - if (queryForResourceOrAgent) { - query.filter(resource.toLatin1()); - } else { - query.resourceFilter(resource.toLatin1()); - } + query.resourceFilter(resource.first().toLatin1()); + query.filter(id.first().toLatin1()); QTime time; time.start(); -- cgit v1.2.3