mirror of https://git.48k.eu/ogcli/
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.master
parent
b1fc9cabb4
commit
c224c596f4
10
ogcli
10
ogcli
|
@ -42,9 +42,15 @@ class CLI():
|
||||||
if not attr.startswith('_')])
|
if not attr.startswith('_')])
|
||||||
args = parser.parse_args(sys.argv[1:2])
|
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):
|
if not hasattr(self.ogcli, args.command):
|
||||||
parser.print_help()
|
print('Invalid subcommand', file=sys.stderr)
|
||||||
sys.exit('Unknown command')
|
parser.print_help(file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# Call the command with the same name.
|
# Call the command with the same name.
|
||||||
getattr(self.ogcli, args.command)(sys.argv[2:])
|
getattr(self.ogcli, args.command)(sys.argv[2:])
|
||||||
|
|
Loading…
Reference in New Issue