#!/usr/bin/env python

from argparse import ArgumentParser
from getpass import getuser
from os import path

from whatidid import commands

class Main(object):
    ''' Main class for whatidid (wid).

    A plain text way of remembering what you did
    '''

    def __init__(self, **kwargs):
        self.command = kwargs.get('command', 'notfound');
        self.message = kwargs.get('message', None)
        if not self.command == 'init':
            if not path.exists('%s/.widrc' % (path.expanduser('~'))):
                print u'wid is not setup properly, you should run: wid init'
                exit(1)
        getattr(self, 'command_' + self.command.replace('-','_'))()

    def command_init(self):
        command = commands.InitCommand()
        command.run()

    def command_update(self):
        command = commands.UpdateCommand(message=self.message)
        command.run()

    def command_update_show(self):
        command = commands.UpdateShowCommand()
        command.run()

    def command_notfound(self):
        print u'The command was not found'
        exit(1);


if __name__ == '__main__':
    parser = ArgumentParser(description=u'Keeping track of what you did this week')
    parser.add_argument('command', metavar='COMMAND', type=str,
        help=u'A command, ie: update, update-show, update-mail')
    parser.add_argument('-m', '--message', type=str, metavar='"A message"', help=u'A message')
    args = parser.parse_args()
    main = Main(command=args.command,
                message=args.message)

