From 7c650aeeca8118e3ca17484840e7e3c986b89d01 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Tue, 1 Aug 2017 10:49:29 +0100 Subject: [PATCH] tools: ratbagctl: add "name" command to return the device name Signed-off-by: Benjamin Tissoires --- tools/ratbagctl.in | 11 +++++++++++ tools/ratbagctl.test.in | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/tools/ratbagctl.in b/tools/ratbagctl.in index b6b88f60..fd65927f 100755 --- a/tools/ratbagctl.in +++ b/tools/ratbagctl.in @@ -523,6 +523,11 @@ def func_profile_disable(r, args): d.commit() +def func_device_name_get(r, args): + d = find_device(r, args) + print(d.name) + + ################################################################################ # these are definitions to be reused in the dict that defines our language @@ -638,6 +643,12 @@ parser_def = [ func: show_device, group: 'Device', }, + { + of_type: command, + name: 'name', + help_str: 'Returns the device name', + func: func_device_name_get, + }, { of_type: switch, name: 'profile', diff --git a/tools/ratbagctl.test.in b/tools/ratbagctl.test.in index 58396ae8..4c859874 100755 --- a/tools/ratbagctl.test.in +++ b/tools/ratbagctl.test.in @@ -116,6 +116,14 @@ class TestRatbagCtlInfo(TestRatbagCtl): self.launch_fail_test("info X") +class TestRatbagCtlName(TestRatbagCtl): + def test_get(self): + r = self.launch_good_test("name test_device") + self.assertEqual(r, 'Test device') + self.launch_fail_test("name test_device X") + self.launch_fail_test("name X") + + class TestRatbgagCtlProfile(TestRatbagCtl): @classmethod def setUpClass(cls):