From c224c596f44fa043f16cb29e17ea28bccfd87bfb Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Fri, 6 Oct 2023 10:49:10 +0200 Subject: ogcli: improve handling of subcommand errors If no subcommand or an invalid one is specified print an error message followed by ogcli --help. Also exit with status code 1. --- ogcli | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'ogcli') diff --git a/ogcli b/ogcli index 078a07e..4adc5cf 100755 --- a/ogcli +++ b/ogcli @@ -42,9 +42,15 @@ class CLI(): if not attr.startswith('_')]) args = parser.parse_args(sys.argv[1:2]) + if args.command is None: + print('Missing subcommand', file=sys.stderr) + parser.print_help(file=sys.stderr) + sys.exit(1) + if not hasattr(self.ogcli, args.command): - parser.print_help() - sys.exit('Unknown command') + print('Invalid subcommand', file=sys.stderr) + parser.print_help(file=sys.stderr) + sys.exit(1) # Call the command with the same name. getattr(self.ogcli, args.command)(sys.argv[2:]) -- cgit v1.2.3-18-g5258