#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Usage:
  sp-grep [-s] <package>...

Options:
  -h --help     Show this screen.
"""
from docopt import docopt
from pkg_resources import DistributionNotFound, get_distribution


def has_any_distribution(names, silent=False):
    for name in names:
        try:
            get_distribution(name)
        except DistributionNotFound:
            continue

        if not silent:
            print('Package {name} found!'.format(name=name))

        exit(0)

    if not silent:
        print('Not found.')

    exit(1)


def main():
    args = docopt(__doc__, version='sp-grep')
    has_any_distribution(names=args['<package>'], silent=args['-s'])


if __name__ == '__main__':
    main()