<commit_before>"""
Collections of entrypoints
"""
import sys

from onelogin_aws_cli import DEFAULT_CONFIG_PATH, OneloginAWS
from onelogin_aws_cli.argparse import OneLoginAWSArgumentParser
from onelogin_aws_cli.configuration import ConfigurationFile


def _load_config(parser, config_file: ConfigurationFile, args=sys.argv[1:]):
    cli_args = parser.parse_args(args)

    with open(DEFAULT_CONFIG_PATH, 'a+') as fp:
        fp.seek(0, 0)
        config_file.file = fp
        config_file.load()

    if (cli_args.configure or not config_file.is_initialised):
        config_file.initialise(cli_args.config_name)

    config_section = config_file.section(cli_args.config_name)

    if config_section is None:
        sys.exit(
            "Configuration '{}' not defined. "
            "Please run 'onelogin-aws-login -c'".format(
                cli_args.config_name
            )
        )

    return config_section, cli_args


def login(args=sys.argv[1:]):
    """
    Entrypoint for `onelogin-aws-login`
    :param args:
    """

    cfg = ConfigurationFile()
    parser = OneLoginAWSArgumentParser()
    config_section, args = _load_config(parser, cfg, args)

    # Handle legacy `--renewSeconds` option while it is deprecated
    if args.renew_seconds or args.renew_seconds_legacy:
        print("ERROR: --renewSeconds  and --renew-seconds have been "
              "deprecated due to longer AWS STS sessions.")
        print("These options will be removed completely in a future version.")
        sys.exit(1)

    config_section.set_overrides(vars(args))

    api = OneloginAWS(config_section)
    api.save_credentials()<commit_msg>Add better error handling (#91)<commit_after>"""
Collections of entrypoints
"""
import sys

from os import environ

from onelogin_aws_cli import DEFAULT_CONFIG_PATH, OneloginAWS
from onelogin_aws_cli.argparse import OneLoginAWSArgumentParser
from onelogin_aws_cli.configuration import ConfigurationFile


def _load_config(parser, config_file: ConfigurationFile, args=sys.argv[1:]):
    cli_args = parser.parse_args(args)

    with open(DEFAULT_CONFIG_PATH, 'a+') as fp:
        fp.seek(0, 0)
        config_file.file = fp
        config_file.load()

    if (cli_args.configure or not config_file.is_initialised):
        config_file.initialise(cli_args.config_name)

    config_section = config_file.section(cli_args.config_name)

    if config_section is None:
        sys.exit(
            "Configuration '{}' not defined. "
            "Please run 'onelogin-aws-login -c'".format(
                cli_args.config_name
            )
        )

    return config_section, cli_args


def login(args=sys.argv[1:]):
    """
    Entrypoint for `onelogin-aws-login`
    :param args:
    """

    debug = environ.get('ONELOGIN_AWS_CLI_DEBUG', '0') == '1'
    try:

        cfg = ConfigurationFile()
        parser = OneLoginAWSArgumentParser()
        config_section, args = _load_config(parser, cfg, args)

        # Handle legacy `--renewSeconds` option while it is deprecated
        if args.renew_seconds or args.renew_seconds_legacy:
            print("ERROR: --renewSeconds  and --renew-seconds have been "
                  "deprecated due to longer AWS STS sessions.")
            print("These options will be removed completely in "
                  "a future version.")
            sys.exit(1)

        config_section.set_overrides(vars(args))

        api = OneloginAWS(config_section)
        api.save_credentials()

    except Exception as e:
        if debug:
            raise e

        print(str(e))
        sys.exit(1)
{'fraction_non_alphanumeric': 0.0929451287793953, 'fraction_numerical': 0.0041993281075028, 'mean_word_length': 2.829581993569132, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5074625', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1071, 'n_words': 254}