diff --git a/src/powerprofilesctl b/src/powerprofilesctl index 83c151d..e50bab0 100755 --- a/src/powerprofilesctl +++ b/src/powerprofilesctl @@ -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) diff --git a/tests/integration_test.py b/tests/integration_test.py index f4a9330..aa7d892 100644 --- a/tests/integration_test.py +++ b/tests/integration_test.py @@ -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()