#!/usr/bin/env python3
"""Check the complexity of a password.

PYTHON_ARGCOMPLETE_OK
"""
from string import ascii_lowercase, ascii_uppercase, digits, punctuation

from milc import cli
from milc.questions import password


@cli.entrypoint('Check the complexity of a password.')
def main(cli):
    c_lower = 0
    c_upper = 0
    c_digits = 0
    c_punctuation = 0
    c_other = 0
    pw = password('Password to check:')

    if not pw:
        cli.log.error('No password provided!')
        return 1

    for char in pw:
        if char in ascii_lowercase:
            c_lower += 1
        elif char in ascii_uppercase:
            c_upper += 1
        elif char in digits:
            c_digits += 1
        elif char in punctuation:
            c_punctuation += 1
        else:
            c_other += 1

    num_types = (c_lower > 0) + (c_upper > 0) + (c_digits > 0) + (c_punctuation > 0) + (c_other > 0)
    cli.log.info('Found %d characters in the password!', len(pw))
    cli.log.info('Found characters in %d different character classes!', num_types)
    return 0


if __name__ == '__main__':
    exit(cli())
