mirror of
https://gitlab.freedesktop.org/upower/power-profiles-daemon.git
synced 2026-05-09 04:48:08 +02:00
src/powerprofilesctl: Fail if a launch unknown argument is before than command
This commit is contained in:
parent
acd17bd066
commit
9bc5643950
2 changed files with 27 additions and 1 deletions
|
|
@ -204,13 +204,28 @@ def get_parser():
|
|||
return parser
|
||||
|
||||
|
||||
def check_unknown_args(args, unknown_args, cmd):
|
||||
if cmd != "launch":
|
||||
return False
|
||||
|
||||
for idx, unknown_arg in enumerate(unknown_args):
|
||||
arg = args[idx]
|
||||
if arg == cmd:
|
||||
return True
|
||||
if unknown_arg == arg:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def main():
|
||||
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":
|
||||
|
||||
if check_unknown_args(sys.argv[1:], unknown, args.command):
|
||||
args.arguments += unknown
|
||||
unknown = []
|
||||
|
||||
|
|
|
|||
|
|
@ -1749,6 +1749,17 @@ class Tests(dbusmock.DBusTestCase):
|
|||
stderr=subprocess.PIPE,
|
||||
)
|
||||
|
||||
def test_launch_arguments_invalid(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 + ["--foo-arg", "launch", "true"], stderr=subprocess.PIPE
|
||||
)
|
||||
|
||||
def test_vanishing_hold(self):
|
||||
self.create_platform_profile()
|
||||
self.start_daemon()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue