diff options
author | Jose M. Guisado <jguisado@soleta.eu> | 2023-10-06 10:49:10 +0200 |
---|---|---|
committer | Jose M. Guisado <jguisado@soleta.eu> | 2023-10-06 10:49:10 +0200 |
commit | c224c596f44fa043f16cb29e17ea28bccfd87bfb (patch) | |
tree | 8af567795bae1345d4358398dcb273a78de32a91 | |
parent | b1fc9cabb46719f2b9319ead63cafea7a745f710 (diff) |
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.
-rwxr-xr-x | ogcli | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -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:]) |