summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2023-10-06 10:49:10 +0200
committerJose M. Guisado <jguisado@soleta.eu>2023-10-06 10:49:10 +0200
commitc224c596f44fa043f16cb29e17ea28bccfd87bfb (patch)
tree8af567795bae1345d4358398dcb273a78de32a91
parentb1fc9cabb46719f2b9319ead63cafea7a745f710 (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-xogcli10
1 files changed, 8 insertions, 2 deletions
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:])