From 3a3b11ade437c55a1dd333c8e4805d2bd6decc6e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 30 Jul 2019 18:59:21 +1000 Subject: [PATCH] ratbagctl: autogenerate the choices list for the specials and led modes Let's not maintain that list manually if we can fetch it from the enums. Signed-off-by: Peter Hutterer --- tools/ratbagctl.in | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/tools/ratbagctl.in b/tools/ratbagctl.in index b7c4b3c2..f3244afc 100755 --- a/tools/ratbagctl.in +++ b/tools/ratbagctl.in @@ -31,6 +31,13 @@ import re from ratbagd import Ratbagd, RatbagdDevice, RatbagdProfile, RatbagdMacro, RatbagdResolution, RatbagdButton, RatbagdLed, RatbagdUnavailable, RatbagError, RatbagErrorCode, RatbagErrorCapability # NOQA +def humanize(string): + return string.lower().replace('_', '-') + + +button_special_names = [humanize(e.name) for e in RatbagdButton.ActionSpecial if e.name != "INVALID"] +led_mode_names = [humanize(e.name) for e in RatbagdLed.Mode] + button_specials_strmap = { **{e: e.name.lower().replace("_", "-") for e in RatbagdButton.ActionSpecial}, **{e.name.lower().replace("_", "-"): e for e in RatbagdButton.ActionSpecial} @@ -950,27 +957,7 @@ active profile if none is given.""", name: 'target_special', metavar: 'S', help_str: 'The new special value to assign', - choices: [ - "unknown", - "doubleclick", - "wheel-left", - "wheel-right", - "wheel-up", - "wheel-down", - "ratchet-mode-switch", - "resolution-cycle-up", - "resolution-cycle-down", - "resolution-up", - "resolution-down", - "resolution-alternate", - "resolution-default", - "profile-cycle-up", - "profile-cycle-down", - "profile-up", - "profile-down", - "second-mode", - "battery-level", - ] + choices: button_special_names }, ], func: func_button_action_set_special, @@ -1055,7 +1042,7 @@ active profile if none is given.""", name: 'mode', metavar: 'mode', help_str: 'The mode to set as current', - choices: ['on', 'off', 'cycle', 'breathing'], + choices: led_mode_names, }, ], },