from __future__ import print_function
import sys
import argparse

from . import tester
from .subparsers import decode as _decode
from .subparsers import monitor as _monitor
from .subparsers import dump as _dump
from .subparsers import convert as _convert
from .subparsers import generate_c_source as _generate_c_source
from .errors import Error

# Remove once less users are using the old package structure.
from . import database as db


__author__ = 'Erik Moqvist'
__version__ = '29.2.1'


def _main():
    parser = argparse.ArgumentParser(
        description='Various CAN utilities.')

    parser.add_argument('-d', '--debug', action='store_true')
    parser.add_argument('--version',
                        action='version',
                        version=__version__,
                        help='Print version information and exit.')

    # Workaround to make the subparser required in Python 3.
    subparsers = parser.add_subparsers(title='subcommands',
                                       dest='subcommand')
    subparsers.required = True

    _decode.add_subparser(subparsers)
    _monitor.add_subparser(subparsers)
    _dump.add_subparser(subparsers)
    _convert.add_subparser(subparsers)
    _generate_c_source.add_subparser(subparsers)

    args = parser.parse_args()

    if args.debug:
        args.func(args, __version__)
    else:
        try:
            args.func(args, __version__)
        except BaseException as e:
            sys.exit('error: ' + str(e))

@@ -482,11 +482,11 @@
 '29.
-2.1
+3.0
 '%0A%0A%0A

Version 29.3.0