From aa32b3dd050017d5876a924dd8ffb038285dc465 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Tue, 8 Dec 2015 15:20:26 +0100 Subject: Improves mat's cli behaviour on faulty options `mat` will now show help message --- mat | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mat b/mat index 03a0ce1..e6faac4 100755 --- a/mat +++ b/mat @@ -11,8 +11,8 @@ from libmat import mat from libmat import archive -def parse(): - """ Get, and parse options passed to the program +def create_arg_parser(): + """ Get options passed to the program """ parser = argparse.ArgumentParser(description='Metadata anonymisation toolkit') parser.add_argument('files', nargs='*') @@ -35,7 +35,7 @@ def parse(): info.add_argument('-v', '--version', action='version', version='MAT %s' % mat.__version__) - return parser.parse_args() + return parser def list_meta(class_file, filename, add2archive): @@ -114,7 +114,13 @@ def list_supported(): def main(): """ Main function: get args and launch the appropriate function """ - args = parse() + args = create_arg_parser() + + if len(sys.argv) < 2: # show help when the there is no argument provided + args.print_help() + sys.exit(2) + + args = args.parse_args() # func receives the function corresponding to the options given as parameters if args.display: # only print metadatas -- cgit v1.3