from sys import exit

import argparse

from .commands import dispatch, choices
from .config import get_config
from .utils import merge


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-u', '--base-url',
                        metavar='https://redmine.example.com',
                        help='Base URL of your Redmine installation.')
    parser.add_argument('-S', '--no-ssl-verify', dest='ssl_verify',
                        action='store_const', const=False)
    parser.add_argument('-k', '--api-key',
                        help='Your Redmine API key.')
    parser.add_argument('-C', '--config-file',
                        help='Override default config path.')
    parser.add_argument('cmd',
                        choices=choices,
                        help='Command to execute.')
    parser.add_argument('args',
                        nargs=argparse.REMAINDER,
                        help='Arguments to command. Use --help to get '
                             'command-specific help.')

    args = vars(parser.parse_args())
    conf = get_config(args.pop('config_file'))

    cmd = args.pop('cmd')
    cmd_args = args.pop('args')
    merged_conf = merge(conf, args)

    return dispatch(cmd, cmd_args, merged_conf)


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

@@ -127,16 +127,23 @@
 rt merge
+, error
 %0A%0A%0Adef m
@@ -232,16 +232,52 @@
 e-url',%0A
+                        dest='url',%0A
         
@@ -568,24 +568,60 @@
 --api-key',%0A
+                        dest='key',%0A
             
@@ -1285,16 +1285,211 @@
  args)%0A%0A
+    required = %5B'url', 'key'%5D%0A    missing = lambda x: bool(merged_conf.get(x))%0A    if not all(map(missing, required)):%0A        error('fatal: base_url and api_key are required')%0A        return 1%0A%0A
     retu

Fix exception when required options are missing