import argparse
from botbot import checks, checker

def main():
    parser = argparse.ArgumentParser(description="Manage lab computational resources.")

    # Verbosity options
    verbosity = parser.add_mutually_exclusive_group()
    verbosity.add_argument("-v", "--verbose",
                           help="Print issues and fixes for all files",
                           action="store_true")

    # Path options
    parser.add_argument("path", type=str, default=".", help="Path of the directory to check")
    parser.add_argument("-p", action='store_const',
                        const=checks.has_permission_issues,
                        help='Check for group permissions issues')

    parser.add_argument("-F", action='store_const',
                        const=checks.is_fastq,
                        help='Check for raw FASTQ files')

    parser.add_argument("-s", action='store_const',
                        const=checks.sam_should_compress,
                        help='Check for *.sam files')

    # Initialize the checker
    args = parser.parse_args()

    c = checker.Checker()
    default_checks = [checks.has_permission_issues,
                      checks.is_fastq,
                      checks.sam_should_compress]
    checker_list = [i for i in vars(args).values() if callable(i)]
    if len(checker_list) > 0:
        c.register(checker_list)
    else:
        c.register(default_checks)

    # Check the given directory
    c.check_tree(args.path)

    # Print the list of issues
    c.pretty_print_issues(args.verbose)

if __name__ == '__main__':
    main()
