#!/usr/bin/env python

import argparse
from colorama import init, Fore, Back, Style
from commands import *
import signal
import sys

def signal_handler(signal, frame):
    print("\nInterrupted!")
    sys.exit(0)

def get_configuration(args):
    from os.path import expanduser
    home = expanduser("~")
    config_file = home + '/.localise/config.yml'
    if hasattr(args, config_file):
        config_file = args.config_file

    if not os.path.isfile(config_file):
        print(Fore.RED + 'No configuration file found! Run the following command to create one:' + Style.RESET_ALL)
        print('')
        print('    localize config')
        print('')
        print('You can also create the file manually in your $HOME directory: $HOME/.localise/config.yml')
        print('')
        sys.exit()

    with open(config_file, 'r') as ymlfile:
        cfg = yaml.load(ymlfile)

    return cfg


def command(args):
    if not args.command == 'config':
        configuration = get_configuration(args)

    if args.command == 'push':
        push(configuration, args)
    elif args.command == 'pull':
        pull(configuration, args)
    elif args.command == 'config':
        config(args)
    else:
        sys.exit(Fore.RED + "Not a valid command \"%s\"! Did you mean config, push, or pull?" % (
        args.command) + Style.RESET_ALL)


def parse_args():
    p = argparse.ArgumentParser(description='Localise')
    p.add_argument('command', nargs='?', help='Specify command: push, pull, config')

    p.add_argument("-c", "--config", dest="config_file", help="Specify config file", metavar="FILE")
    p.add_argument('--verbose', '-v', action='count')

    args = p.parse_args()

    return args


def main():
    init(autoreset=True)
    args = parse_args()
    command(args)


if __name__ == '__main__':
    signal.signal(signal.SIGINT, signal_handler)
    main()

@@ -126,16 +126,95 @@
 rt sys%0A%0A
+class ConfigException(Exception):%0A    %22%22%22Raise when config file is invalid%22%22%22%0A%0A
 def sign
@@ -310,24 +310,170 @@
 tion(args):%0A
+    %22%22%22%0A    Parse configuration file%0A%0A    Throw an exception when file does not exists or has wrong format.%0A    :param args:%0A    :return:%0A    %22%22%22%0A
     from os.
@@ -592,16 +592,17 @@
 r(args, 
+'
 config_f
@@ -596,32 +596,33 @@
 gs, 'config_file
+'
 ):%0A        confi
@@ -1100,16 +1100,277 @@
 lfile)%0A%0A
+    if not 'api' in cfg or not 'token' in cfg%5B'api'%5D or not cfg%5B'api'%5D%5B'token'%5D:%0A        raise ConfigException('Missing token value in config file')%0A    if not 'translations' in cfg:%0A        raise ConfigException('No translation files defined in config file')%0A%0A
     retu
@@ -1426,32 +1426,49 @@
 nd == 'config':%0A
+        try:%0A    
         configur
@@ -1498,16 +1498,101 @@
 on(args)
+%0A        except ConfigException as e:%0A            print(e.message)%0A            return
 %0A%0A    if

Validate format of config file