#!/usr/bin/env python3

import AUR.PkgList as APL
import logging
import XCPF

from argparse import ArgumentParser

parser = ArgumentParser(description='Retrieve and print the full list of AUR packages.')
parser.add_argument(
  '-f', '--force', action='store_true',
  help='Force a refresh of the local file.'
)
parser.add_argument(
  '-t', '--time', type=int, default=APL.DEFAULT_TTL,
  help='The time, in seconds, to cache the local file, counted from the last modification. Default: %(default)s'
)
parser.add_argument(
  '-p', '--path',
  help='Set the local file path.'
)
parser.add_argument(
  '-q', '--quiet', action='store_true',
  help='Refresh the local file without printing the list of packages.'
)

def main(args=None):
  pargs = parser.parse_args(args)
  pkglist = APL.PkgList(path=pargs.path, cache_time=pargs.time)
  pkglist.refresh(force=pargs.force)
  if not pargs.quiet:
    for p in pkglist:
      print(p)

if __name__ == '__main__':
  XCGF.configure_logging(level=logging.INFO)
  try:
    main()
  except (KeyboardInterrupt, BrokenPipeError):
    pass
