From cc072e4a2c874b11c4c8617f9b29e5e263f72cd9 Mon Sep 17 00:00:00 2001 From: Matthijs Tijink Date: Mon, 26 Feb 2018 19:39:34 +0100 Subject: [PATCH] Add more scripting helpers to cli command Summary: Adds "--name-only" and "--id-name-only", in addition to the already existing "--id-only". This is useful for the zsh autocompletion which I've written. Test Plan: The output is identical without the new flags. Reviewers: #kde_connect, nicolasfella Reviewed By: #kde_connect, nicolasfella Differential Revision: https://phabricator.kde.org/D10875 --- cli/kdeconnect-cli.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cli/kdeconnect-cli.cpp b/cli/kdeconnect-cli.cpp index 1028743ab..b17de1991 100644 --- a/cli/kdeconnect-cli.cpp +++ b/cli/kdeconnect-cli.cpp @@ -51,6 +51,8 @@ int main(int argc, char** argv) parser.addOption(QCommandLineOption(QStringList(QStringLiteral("l")) << QStringLiteral("list-devices"), i18n("List all devices"))); parser.addOption(QCommandLineOption(QStringList(QStringLiteral("a")) << QStringLiteral("list-available"), i18n("List available (paired and reachable) devices"))); parser.addOption(QCommandLineOption(QStringLiteral("id-only"), i18n("Make --list-devices or --list-available print only the devices id, to ease scripting"))); + parser.addOption(QCommandLineOption(QStringLiteral("name-only"), i18n("Make --list-devices or --list-available print only the devices name, to ease scripting"))); + parser.addOption(QCommandLineOption(QStringLiteral("id-name-only"), i18n("Make --list-devices or --list-available print only the devices id and name, to ease scripting"))); parser.addOption(QCommandLineOption(QStringLiteral("refresh"), i18n("Search for devices in the network and re-establish connections"))); parser.addOption(QCommandLineOption(QStringLiteral("pair"), i18n("Request pairing to a said device"))); parser.addOption(QCommandLineOption(QStringLiteral("ring"), i18n("Find the said device by ringing it."))); @@ -90,9 +92,19 @@ int main(int argc, char** argv) } const QStringList devices = blockOnReply(iface.devices(reachable, paired)); + bool displayCount = true; for (const QString& id : devices) { if (parser.isSet(QStringLiteral("id-only"))) { QTextStream(stdout) << id << endl; + displayCount = false; + } else if (parser.isSet(QStringLiteral("name-only"))) { + DeviceDbusInterface deviceIface(id); + QTextStream(stdout) << deviceIface.name() << endl; + displayCount = false; + } else if (parser.isSet(QStringLiteral("id-name-only"))) { + DeviceDbusInterface deviceIface(id); + QTextStream(stdout) << id << ' ' << deviceIface.name() << endl; + displayCount = false; } else { DeviceDbusInterface deviceIface(id); QString statusInfo; @@ -109,7 +121,7 @@ int main(int argc, char** argv) << ": " << deviceIface.id() << ' ' << statusInfo << endl; } } - if (!parser.isSet(QStringLiteral("id-only"))) { + if (displayCount) { QTextStream(stdout) << i18np("1 device found", "%1 devices found", devices.size()) << endl; } else if (devices.isEmpty()) { QTextStream(stderr) << i18n("No devices found") << endl;