"""Verify

Checks to see if promus can send an email.

"""

import sys
import textwrap
import promus.core.git as git
import promus.core.util as util

DESC = """
this command should be run after running `promus setup` to make sure
that promus can send emails using the email account you specified
during the setup process.

"""


def add_parser(subp, raw):
    "Add a parser to the main subparser. "
    subp.add_parser('verify', help='make sure promus can send emails',
                    formatter_class=raw,
                    description=textwrap.dedent(DESC))


def run(_):
    """Run command. """
    sys.stdout.write('sending email ... ')
    send_to = [git.config('user.email')]
    subject = 'Promus Server Test'
    text = 'This message was generated by promus to make sure promus is ' \
           'able of sending emails.'
    util.send_mail(send_to, subject, text, text)
    sys.stdout.write('done\n')
