#!/usr/bin/env python
import argparse
from biorxivfeed.feed import scrape, remove, list_pubs, add_to_pubs, \
                             DEFAULT_CONF_PATH

parent = argparse.ArgumentParser(add_help=False)
parent.add_argument('-c', '--conf', default=DEFAULT_CONF_PATH,
                   help="path to configuration YAML file")

parser = argparse.ArgumentParser(parents=[parent])
subparsers = parser.add_subparsers(dest='command')
subparsers.required = True

scrape_parser = subparsers.add_parser('scrape', help="scrape bioRxiv")
scrape_parser.add_argument('-d', '--download', action='store_true',
                   help="download pdfs if possible")
scrape_parser.add_argument('-u', '--update', action='store_true',
                   help="update existing pubs (redownload pdfs, etc)")
scrape_parser.set_defaults(func=scrape)

manage_parser = subparsers.add_parser('remove', help="clean publist")
manage_parser.add_argument('dois', nargs='*',
                           help="remove pub from publist and blacklist it")
manage_parser.set_defaults(func=remove)

list_parser = subparsers.add_parser('list', help="list pubs in publist")
list_parser.add_argument('-f', '--fancy', action='store_true',
                         help="print in color on 2 lines")
sorters = list_parser.add_mutually_exclusive_group()
sorters.add_argument('-a', '--author-sort', action='store_true')
sorters.add_argument('-d', '--doi-sort', action='store_true')
sorters.add_argument('-t', '--date-sort', action='store_true')
list_parser.set_defaults(func=list_pubs)

pubs_parser = subparsers.add_parser('pubs', help="add pub to `pubs` repo")
pubs_parser.add_argument('doi', help="doi of pub to add")
pubs_parser.add_argument('-t', '--tags', help="`pubs` tags")
pubs_parser.add_argument('-M', '--move', action='store_true', help="move pdf")
pubs_parser.set_defaults(func=add_to_pubs)

args = parser.parse_args()
args.func(**vars(args))
