def main(cli_arguments: List[str]):
    """
    Entrypoint.
    :param cli_arguments: arguments passed in via the CLI
    :raises SystemExit: always raised
    """
    cli_configuration: CliConfiguration
    try:
        cli_configuration = parse_cli_configuration(cli_arguments)
    except InvalidCliArgumentError as e:
        logger.error(e)
        exit(INVALID_CLI_ARGUMENT_EXIT_CODE)
    except SystemExit as e:
        exit(e.code)

    if cli_configuration.log_verbosity:
        logging.getLogger(PACKAGE_NAME).setLevel(cli_configuration.log_verbosity)

    consul_configuration: ConsulConfiguration
    try:
        consul_configuration = get_consul_configuration_from_environment()
    except KeyError as e:
        logger.error(f"Cannot connect to Consul - the environment variable {e.args[0]} must be set")
        exit(MISSING_REQUIRED_ENVIRONMENT_VARIABLE_EXIT_CODE)
    except InvalidEnvironmentVariableError as e:
        logger.error(e)
        exit(INVALID_ENVIRONMENT_VARIABLE_EXIT_CODE)

    lock_manager: ConsulLockManager
    try:
        lock_manager = ConsulLockManager(
            consul_configuration=consul_configuration, session_ttl_in_seconds=cli_configuration.session_ttl)
    except InvalidSessionTtlValueError as e:
        logger.error(e)
        exit(INVALID_SESSION_TTL_EXIT_CODE)

    try:
        {
            CliLockConfiguration: _acquire_lock_and_exit,
            CliLockAndExecuteConfiguration: _acquire_lock_and_execute,
            CliUnlockConfiguration: _release_lock
        }[type(cli_configuration)](lock_manager, cli_configuration)
    except PermissionDeniedConsulError as e:
        error_message = f"Invalid credentials - are you sure you have set {CONSUL_TOKEN_ENVIRONMENT_VARIABLE} " \
                        f"correctly?"
        logger.debug(e)
        logger.error(error_message)
        exit(PERMISSION_DENIED_EXIT_CODE)
    except DoubleSlashKeyError as e:
        logger.debug(e)
        logger.error(f"Double slashes \"//\" in keys get converted into single slashes \"/\" - please use a "
                     f"single slash if this is intended: {cli_configuration.key}")
        exit(INVALID_KEY_EXIT_CODE)
    except NonNormalisedKeyError as e:
        logger.debug(e)
        logger.error(f"Key paths must be normalised - use \"{normpath(e.key)}\" if this key was intended: "
                     f"{cli_configuration.key}")
        exit(INVALID_KEY_EXIT_CODE)
def main ( cli_arguments : List [ str ] ) : cli_configuration : CliConfiguration try : cli_configuration = parse_cli_configuration ( cli_arguments ) except InvalidCliArgumentError as e : logger . error ( e ) exit ( INVALID_CLI_ARGUMENT_EXIT_CODE ) except SystemExit as e : exit ( e . code ) if cli_configuration . log_verbosity : logging . getLogger ( PACKAGE_NAME ) . setLevel ( cli_configuration . log_verbosity ) consul_configuration : ConsulConfiguration try : consul_configuration = get_consul_configuration_from_environment ( ) except KeyError as e : logger . error ( f"Cannot connect to Consul - the environment variable {e.args[0]} must be set" ) exit ( MISSING_REQUIRED_ENVIRONMENT_VARIABLE_EXIT_CODE ) except InvalidEnvironmentVariableError as e : logger . error ( e ) exit ( INVALID_ENVIRONMENT_VARIABLE_EXIT_CODE ) lock_manager : ConsulLockManager try : lock_manager = ConsulLockManager ( consul_configuration = consul_configuration , session_ttl_in_seconds = cli_configuration . session_ttl ) except InvalidSessionTtlValueError as e : logger . error ( e ) exit ( INVALID_SESSION_TTL_EXIT_CODE ) try : { CliLockConfiguration : _acquire_lock_and_exit , CliLockAndExecuteConfiguration : _acquire_lock_and_execute , CliUnlockConfiguration : _release_lock } [ type ( cli_configuration ) ] ( lock_manager , cli_configuration ) except PermissionDeniedConsulError as e : error_message = f"Invalid credentials - are you sure you have set {CONSUL_TOKEN_ENVIRONMENT_VARIABLE} " f"correctly?" logger . debug ( e ) logger . error ( error_message ) exit ( PERMISSION_DENIED_EXIT_CODE ) except DoubleSlashKeyError as e : logger . debug ( e ) logger . error ( f"Double slashes \"//\" in keys get converted into single slashes \"/\" - please use a " f"single slash if this is intended: {cli_configuration.key}" ) exit ( INVALID_KEY_EXIT_CODE ) except NonNormalisedKeyError as e : logger . debug ( e ) logger . error ( f"Key paths must be normalised - use \"{normpath(e.key)}\" if this key was intended: " f"{cli_configuration.key}" ) exit ( INVALID_KEY_EXIT_CODE )
Entrypoint.
    :param cli_arguments: arguments passed in via the CLI
    :raises SystemExit: always raised