From 6f8b4fd6f9ba764024c9f9da61169ede0bc1a113 Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 10 Jan 2016 10:50:45 +0100 Subject: [PATCH] [patatools] Use built-in features to raise error when no subcommand is provided --- patacrep/tools/__main__.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/patacrep/tools/__main__.py b/patacrep/tools/__main__.py index 17f3c8a4..a1aa0515 100644 --- a/patacrep/tools/__main__.py +++ b/patacrep/tools/__main__.py @@ -94,6 +94,8 @@ def commandline_parser(): title="Subcommands", description="List of available subcommands.", ) + subparsers.required = True + subparsers.dest = "subcommand" for command, message, function in sorted(_iter_subcommands(), key=operator.itemgetter(0)): sub1 = subparsers.add_parser(command, help=message, add_help=False) @@ -107,10 +109,7 @@ def main(): parser = commandline_parser() args = parser.parse_args() - if hasattr(args, "function"): - args.function(args.remainder) - else: - parser.error("Missing command.") + args.function(args.remainder) if __name__ == "__main__": main()