diff --git a/src/unisync/argparser.py b/src/unisync/argparser.py index dda0eb0..ba28700 100644 --- a/src/unisync/argparser.py +++ b/src/unisync/argparser.py @@ -3,20 +3,34 @@ import argparse -def create_argparser() -> argparse.ArgumentParser: +def create_argparser(sync_function, add_function, mount_function) -> argparse.ArgumentParser: + """ + Creates an argument parser to parse the command line arguments. + We use subparsers and set a default function for each to perform the correct action. + """ parser = argparse.ArgumentParser( prog='unisync', description='File synchronisation application', - epilog=""" - Copyright © 2025 Paul Retourné. - License GPLv3+: GNU GPL version 3 or later .""" + epilog="Copyright © 2025 Paul Retourné.\n" + "License GPLv3+: GNU GPL version 3 or later .", + formatter_class=argparse.RawDescriptionHelpFormatter ) parser.add_argument("local", nargs="?") parser.add_argument("remote", nargs="?") + parser.set_defaults(func=sync_function) remote_addr_group = parser.add_mutually_exclusive_group() remote_addr_group.add_argument("--ip") remote_addr_group.add_argument("--hostname") parser.add_argument("--config", help="Path to the configuration file", metavar="path_to_config") + + subparsers = parser.add_subparsers(help='Actions other than synchronisation') + + parser_add = subparsers.add_parser('add', help='Add files to be synchronised.') + parser_add.set_defaults(func=add_function) + + parser_mount = subparsers.add_parser('mount', help='Mount the remote.') + parser_mount.set_defaults(func=mount_function) + return parser