diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-16 10:34:22 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-16 10:34:22 +0100 |
commit | 71d27b4b016240e4a5ae28c59991317dec2fdcd4 (patch) | |
tree | 9f93eb11f569f21df8d628ec626fe76e7e41c8fd /sinksh/syntax_modules/sink_list.cpp | |
parent | 9bd53f793c6eb1b3ce9a866d226fbb07a8036ff7 (diff) | |
download | sink-71d27b4b016240e4a5ae28c59991317dec2fdcd4.tar.gz sink-71d27b4b016240e4a5ae28c59991317dec2fdcd4.zip |
sinksh list: allow the user to specify what to print
Diffstat (limited to 'sinksh/syntax_modules/sink_list.cpp')
-rw-r--r-- | sinksh/syntax_modules/sink_list.cpp | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/sinksh/syntax_modules/sink_list.cpp b/sinksh/syntax_modules/sink_list.cpp index 8507d48..60a70c1 100644 --- a/sinksh/syntax_modules/sink_list.cpp +++ b/sinksh/syntax_modules/sink_list.cpp | |||
@@ -40,14 +40,16 @@ | |||
40 | namespace SinkList | 40 | namespace SinkList |
41 | { | 41 | { |
42 | 42 | ||
43 | bool list(const QStringList &args, State &state) | 43 | bool list(const QStringList &args_, State &state) |
44 | { | 44 | { |
45 | if (args.isEmpty()) { | 45 | if (args_.isEmpty()) { |
46 | state.printError(QObject::tr("Please provide at least one type to list (e.g. resource, ..")); | 46 | state.printError(QObject::tr("Please provide at least one type to list (e.g. resource, ..")); |
47 | return false; | 47 | return false; |
48 | } | 48 | } |
49 | 49 | ||
50 | auto type = !args.isEmpty() ? args.at(0) : QString(); | 50 | auto args = args_; |
51 | |||
52 | auto type = args.takeFirst(); | ||
51 | 53 | ||
52 | if (!type.isEmpty() && !SinkshUtils::isValidStoreType(type)) { | 54 | if (!type.isEmpty() && !SinkshUtils::isValidStoreType(type)) { |
53 | state.printError(QObject::tr("Unknown type: %1").arg(type)); | 55 | state.printError(QObject::tr("Unknown type: %1").arg(type)); |
@@ -58,6 +60,7 @@ bool list(const QStringList &args, State &state) | |||
58 | 60 | ||
59 | auto filterIndex = args.indexOf("--filter"); | 61 | auto filterIndex = args.indexOf("--filter"); |
60 | if (filterIndex >= 0) { | 62 | if (filterIndex >= 0) { |
63 | args.removeAt(filterIndex); | ||
61 | for (int i = 1; i < filterIndex; i++) { | 64 | for (int i = 1; i < filterIndex; i++) { |
62 | query.resourceFilter(args.at(i).toLatin1()); | 65 | query.resourceFilter(args.at(i).toLatin1()); |
63 | } | 66 | } |
@@ -68,20 +71,39 @@ bool list(const QStringList &args, State &state) | |||
68 | 71 | ||
69 | } | 72 | } |
70 | 73 | ||
71 | query.requestedProperties = SinkshUtils::requestedProperties(type); | 74 | auto allIndex = args.indexOf("--all"); |
72 | 75 | if (allIndex >= 0) { | |
73 | QStringList line; | 76 | args.removeAt(allIndex); |
74 | line << QObject::tr("Resource") << QObject::tr("Identifier"); | 77 | } else { |
75 | for (const auto &prop: query.requestedProperties) { | 78 | if (!args.isEmpty()) { |
76 | line << prop; | 79 | std::transform(args.constBegin(), args.constEnd(), std::back_inserter(query.requestedProperties), [] (const QString &s) { return s.toLatin1(); }); |
80 | } else { | ||
81 | query.requestedProperties = SinkshUtils::requestedProperties(type); | ||
82 | } | ||
77 | } | 83 | } |
78 | state.stageTableLine(line); | 84 | |
85 | QStringList tableLine; | ||
86 | QByteArrayList toPrint; | ||
79 | 87 | ||
80 | for (const auto &o : SinkshUtils::getStore(type).read(query)) { | 88 | for (const auto &o : SinkshUtils::getStore(type).read(query)) { |
89 | if (tableLine.isEmpty()) { | ||
90 | tableLine << QObject::tr("Resource") << QObject::tr("Identifier"); | ||
91 | if (query.requestedProperties.isEmpty()) { | ||
92 | auto in = o.availableProperties(); | ||
93 | toPrint = o.availableProperties(); | ||
94 | std::transform(in.constBegin(), in.constEnd(), std::back_inserter(tableLine), [] (const QByteArray &s) -> QString { return s; }); | ||
95 | } else { | ||
96 | auto in = query.requestedProperties; | ||
97 | toPrint = query.requestedProperties; | ||
98 | std::transform(in.constBegin(), in.constEnd(), std::back_inserter(tableLine), [] (const QByteArray &s) -> QString { return s; }); | ||
99 | } | ||
100 | state.stageTableLine(tableLine); | ||
101 | } | ||
102 | |||
81 | QStringList line; | 103 | QStringList line; |
82 | line << o.resourceInstanceIdentifier(); | 104 | line << o.resourceInstanceIdentifier(); |
83 | line << o.identifier(); | 105 | line << o.identifier(); |
84 | for (const auto &prop: query.requestedProperties) { | 106 | for (const auto &prop: toPrint) { |
85 | const auto value = o.getProperty(prop); | 107 | const auto value = o.getProperty(prop); |
86 | if (value.isValid()) { | 108 | if (value.isValid()) { |
87 | if (value.canConvert<QString>()) { | 109 | if (value.canConvert<QString>()) { |