@click.command(context_settings=CONTEXT_SETTINGS, cls=ConfigurableLoader)
@click.version_option(version=__version__, message='%(prog)s %(version)s')
@click.option('-d', '--debug/--no-debug', default=False,
              help=('Drop into the debugger if the command execution raises '
                    'an exception.'))
@click.option('--help-all', is_flag=True, is_eager=True, expose_value=False,
              callback=ConfigurableLoader.show_help_all,
              help='Show this message including hidden subcommands.')
@click.pass_context
def main(ctx, debug):
    # TODO: Enable this using a command line switch
    # import logging
    # logging.basicConfig(level=logging.DEBUG)

    if debug:
        def exception_handler(type, value, traceback):
            click.secho('\nAn exception occurred while executing the '
                        'requested command:', fg='red')
            hr(fg='red')
            sys.__excepthook__(type, value, traceback)

            click.secho('\nAs requested I will now drop you inside an '
                        'interactive debugging session:', fg='red')
            hr(fg='red')

            pdb.post_mortem(traceback)
        sys.excepthook = exception_handler

    try:
        integration_helper = ShellIntegrationHelper(
            os.environ['LANCET_SHELL_HELPER'])
    except KeyError:
        integration_helper = WarnIntegrationHelper()

    if os.path.exists(PROJECT_CONFIG):
        config = load_config(PROJECT_CONFIG)
    else:
        config = load_config()

    ctx.obj = Lancet(config, integration_helper)
    ctx.obj.call_on_close = ctx.call_on_close
    ctx.call_on_close(integration_helper.close)

    sentry_dsn = config.get('lancet', 'sentry_dsn')
    if sentry_dsn and not debug:
        if not raven:
            click.secho('You provided a Sentry DSN but the raven module is '
                        'not installed. Sentry logging will not be enabled.',
                        fg='yellow')
        else:
            sentry_client = get_sentry_client(sentry_dsn)

            def exception_handler(type, value, traceback):
                settings_diff = diff_config(
                    load_config(DEFAULT_CONFIG, defaults=False),
                    config,
                    exclude=set([
                        ('lancet', 'sentry_dsn'),
                    ])
                )

                sys.__excepthook__(type, value, traceback)

                if type in IGNORED_EXCEPTIONS:
                    return

                click.echo()
                hr(fg='yellow')

                click.secho('\nAs requested, I am sending details about this '
                            'error to Sentry, please report the following ID '
                            'when seeking support:')

                error_id = sentry_client.captureException(
                    (type, value, traceback),
                    extra={
                        'settings': as_dict(settings_diff),
                        'working_dir': os.getcwd(),
                    },
                )[0]
                click.secho('\n    {}\n'.format(error_id), fg='yellow')
            sys.excepthook = exception_handler
dataset/ETHPy150Open GaretJax/lancet/lancet/cli.py/main/original