From 436ab1cb70f941f9a93a87a7e99f92b9a282cec3 Mon Sep 17 00:00:00 2001 From: lennard Date: Tue, 20 Jun 2023 15:12:56 +0200 Subject: [PATCH 1/5] Print an error message when no device is found. --- rivalcfg/__main__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rivalcfg/__main__.py b/rivalcfg/__main__.py index 72045c6..4bdc34e 100644 --- a/rivalcfg/__main__.py +++ b/rivalcfg/__main__.py @@ -76,6 +76,9 @@ def main(args=sys.argv[1:]): ): try: mouse = get_first_mouse() + if not mouse: + print("E: No supported device found.") + sys.exit(1) except IOError as error: if "--help" not in sys.argv and "-h" not in sys.argv: raise error From ebc129e061cec3610dcb77d8ab1595989212a295 Mon Sep 17 00:00:00 2001 From: lennard Date: Tue, 20 Jun 2023 15:14:23 +0200 Subject: [PATCH 2/5] Fixed two typos --- rivalcfg/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rivalcfg/cli.py b/rivalcfg/cli.py index 060ba4f..a428cc0 100644 --- a/rivalcfg/cli.py +++ b/rivalcfg/cli.py @@ -77,7 +77,7 @@ def __call__(self, parser, namespace, value, option_string=None): class PrintDebugAction(argparse.Action): - """Prints debug informations and exit.""" + """Prints debug information and exit.""" def __call__(self, parser, namespace, value, option_string=None): print(debug.get_debug_info()) @@ -126,7 +126,7 @@ def add_main_cli(cli_parser): cli_parser.add_argument( "--print-debug", - help="Prints debug informations and exit", + help="Prints debug information and exit", nargs=0, action=PrintDebugAction, ) From b24755c1f5e9f79b187508f794f86de8e64f3df8 Mon Sep 17 00:00:00 2001 From: lennard Date: Tue, 20 Jun 2023 15:19:09 +0200 Subject: [PATCH 3/5] Before showing a no device found error check if help should be printed instead. --- rivalcfg/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rivalcfg/__main__.py b/rivalcfg/__main__.py index 4bdc34e..ee12475 100644 --- a/rivalcfg/__main__.py +++ b/rivalcfg/__main__.py @@ -76,7 +76,7 @@ def main(args=sys.argv[1:]): ): try: mouse = get_first_mouse() - if not mouse: + if "--help" not in sys.argv and "-h" not in sys.argv and not mouse: print("E: No supported device found.") sys.exit(1) except IOError as error: From fc00642a569299cf83494ae2dc92d9f1aab648b9 Mon Sep 17 00:00:00 2001 From: lennard Date: Sat, 24 Jun 2023 11:19:27 +0200 Subject: [PATCH 4/5] Changed occurrences of `sys.argv` in main to `args`. --- rivalcfg/__main__.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/rivalcfg/__main__.py b/rivalcfg/__main__.py index ee12475..5df7409 100644 --- a/rivalcfg/__main__.py +++ b/rivalcfg/__main__.py @@ -58,7 +58,7 @@ def _render_battery_level(level=None, is_charging=None): def main(args=sys.argv[1:]): # Display a message when no argument given - if len(sys.argv) == 1: + if not args: print("USAGE:\n rivalcfg --help") sys.exit(1) @@ -68,19 +68,19 @@ def main(args=sys.argv[1:]): # Try to open a mouse mouse = None if ( - "--print-debug" not in sys.argv - and "--list" not in sys.argv - and "--version" not in sys.argv - and "--update-udev" not in sys.argv - and "--print-udev" not in sys.argv + "--print-debug" not in args + and "--list" not in args + and "--version" not in args + and "--update-udev" not in args + and "--print-udev" not in args ): try: mouse = get_first_mouse() - if "--help" not in sys.argv and "-h" not in sys.argv and not mouse: + if "--help" not in args and "-h" not in args and not mouse: print("E: No supported device found.") sys.exit(1) except IOError as error: - if "--help" not in sys.argv and "-h" not in sys.argv: + if "--help" not in args and "-h" not in args: raise error cli_parser = argparse.ArgumentParser(prog="rivalcfg", epilog=_EPILOG) From 8896f1ce53a34c33ea750ee5ec9e577eb0d3adb7 Mon Sep 17 00:00:00 2001 From: Fabien LOISON Date: Tue, 4 Jul 2023 13:30:39 +0200 Subject: [PATCH 5/5] Moved a test ouside a try close --- rivalcfg/__main__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rivalcfg/__main__.py b/rivalcfg/__main__.py index 5df7409..2f8454c 100644 --- a/rivalcfg/__main__.py +++ b/rivalcfg/__main__.py @@ -76,13 +76,14 @@ def main(args=sys.argv[1:]): ): try: mouse = get_first_mouse() - if "--help" not in args and "-h" not in args and not mouse: - print("E: No supported device found.") - sys.exit(1) except IOError as error: if "--help" not in args and "-h" not in args: raise error + if not mouse and "--help" not in args and "-h" not in args: + print("E: No supported device found.") + sys.exit(1) + cli_parser = argparse.ArgumentParser(prog="rivalcfg", epilog=_EPILOG) cli.add_main_cli(cli_parser)