powerprofilesctl: Throw an unrecognized arguments error on on launch-commands

This commit is contained in:
Marco Trevisan (Treviño) 2024-04-01 14:12:19 +02:00 committed by Mario Limonciello
parent 8574070267
commit acd17bd066
2 changed files with 30 additions and 1 deletions

View file

@ -205,12 +205,19 @@ def get_parser():
def main():
args, unknown = get_parser().parse_known_args()
parser = get_parser()
args, unknown = parser.parse_known_args()
# default behavior is to run list if no command is given
if not args.command:
args.func = _list
if args.command == "launch":
args.arguments += unknown
unknown = []
if unknown:
msg = argparse._("unrecognized arguments: %s")
parser.error(msg % " ".join(unknown))
args.func(args)

View file

@ -1727,6 +1727,28 @@ class Tests(dbusmock.DBusTestCase):
)
self.assertEqual(tmpf.readlines(), ["--foo --bar -v arg\n"])
def test_unknown_action(self):
self.create_platform_profile()
self.start_daemon()
self.assert_eventually(lambda: self.get_dbus_property("ActiveProfile"))
with self.assertRaises(subprocess.CalledProcessError):
tool_cmd = self.powerprofilesctl_command()
subprocess.check_output(
tool_cmd + ["hopefully-invalid-action"], stderr=subprocess.PIPE
)
def test_unknown_list_argument(self):
self.create_platform_profile()
self.start_daemon()
self.assert_eventually(lambda: self.get_dbus_property("ActiveProfile"))
with self.assertRaises(subprocess.CalledProcessError):
subprocess.check_output(
self.powerprofilesctl_command() + ["list", "--invalid-argument"],
stderr=subprocess.PIPE,
)
def test_vanishing_hold(self):
self.create_platform_profile()
self.start_daemon()