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.
This commit is contained in:
2025-04-21 10:50:20 +02:00
parent 0e513cd179
commit 6cd351d8b8

View File

@@ -4,7 +4,7 @@
from argparse import ArgumentParser from argparse import ArgumentParser
from logging import getLogger 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 .. import proginit as pi
from ..dbus_middleware1 import extend_interface from ..dbus_middleware1 import extend_interface
@@ -14,32 +14,15 @@ log = getLogger(__name__)
def add_subparsers(parent_parser: ArgumentParser): def add_subparsers(parent_parser: ArgumentParser):
parent_parser.add_argument( parent_parser.add_argument(
"action", "action",
choices=["enable", "disable", "status", "available"], choices=["enable", "disable", "status", "available", "list-features"],
help="Action to be executed: enable, disable, status or available", 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( parent_parser.add_argument(
"feature", "feature",
choices=[ nargs="?",
"gui", default="",
"revpi-con-can", help="Name of the feature to configer. To list all features use 'list-features' as action.",
"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",
) )
@@ -48,6 +31,21 @@ def main() -> int:
dbus_value = False dbus_value = False
try: 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": if action == "enable":
simple_call( simple_call(
"Enable", "Enable",