From 6cd351d8b8897d80788657898209cbb4f39e65a4 Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Mon, 21 Apr 2025 10:50:20 +0200 Subject: [PATCH] feat(cli): `Add 'list-features' action to CLI config commands` Introduce a new 'list-features' action to display all available features via CLI. Updated argument handling to make 'feature' optional for 'list-features' and added a validation step to ensure the feature name is provided for other actions. --- .../cli_commands/cli_config.py | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/revpi_middleware/cli_commands/cli_config.py b/src/revpi_middleware/cli_commands/cli_config.py index ed8548a..d91b39c 100644 --- a/src/revpi_middleware/cli_commands/cli_config.py +++ b/src/revpi_middleware/cli_commands/cli_config.py @@ -4,7 +4,7 @@ from argparse import ArgumentParser from logging import getLogger -from .dbus_helper import BusType, simple_call +from .dbus_helper import BusType, get_properties, simple_call from .. import proginit as pi from ..dbus_middleware1 import extend_interface @@ -14,32 +14,15 @@ log = getLogger(__name__) def add_subparsers(parent_parser: ArgumentParser): parent_parser.add_argument( "action", - choices=["enable", "disable", "status", "available"], - help="Action to be executed: enable, disable, status or available", + choices=["enable", "disable", "status", "available", "list-features"], + help="Action to be executed: enable, disable, status or available. " + "To get all available features, use 'list-features'.", ) - - # Load dynamic features from dbus - simple_call() - parent_parser.add_argument( "feature", - choices=[ - "gui", - "revpi-con-can", - "dphys-swapfile", - "pimodbus-master", - "pimodbus-slave", - "systemd-timesyncd", - "ssh", - "nodered", - "noderedrevpinodes-server", - "revpipyload", - "bluetooth", - "ieee80211", - "avahi", - "external-antenna", - ], - help="Name des Features, das konfiguriert werden soll", + nargs="?", + default="", + help="Name of the feature to configer. To list all features use 'list-features' as action.", ) @@ -48,6 +31,21 @@ def main() -> int: dbus_value = False try: + if action == "list-features": + dbus_value = get_properties( + "available_features", + interface=extend_interface("RevpiConfig"), + bus_type=BusType.SESSION if pi.pargs.use_session_bus else BusType.SYSTEM, + ) + for feature in dbus_value: + print(feature) + + return 0 + + # For the following actions, a feature name is required + if pi.pargs.feature == "": + raise Exception("Feature name is required") + if action == "enable": simple_call( "Enable",