<commit_before>"""
syslog2irc.argparser
~~~~~~~~~~~~~~~~~~~~

Command line argument parsing

:Copyright: 2007-2021 <NAME>
:License: MIT, see LICENSE for details.
"""

from argparse import ArgumentParser
import dataclasses

from .irc import IrcServer


DEFAULT_IRC_PORT = IrcServer('').port


def parse_args(args=None):
    """Parse command line arguments."""
    parser = create_arg_parser()
    parsed = parser.parse_args(args)

    irc_server = parsed.irc_server
    if irc_server is not None:
        parsed.irc_server = dataclasses.replace(
            irc_server, ssl=parsed.irc_server_ssl
        )

    return parsed


def create_arg_parser():
    """Prepare the command line arguments parser."""
    parser = ArgumentParser()

    parser.add_argument(
        '--irc-nickname',
        dest='irc_nickname',
        default='syslog',
        help='the IRC nickname the bot should use',
        metavar='NICKNAME',
    )

    parser.add_argument(
        '--irc-realname',
        dest='irc_realname',
        default='syslog2IRC',
        help='the IRC realname the bot should use',
        metavar='REALNAME',
    )

    parser.add_argument(
        '--irc-server',
        dest='irc_server',
        type=parse_irc_server_arg,
        help='IRC server (host and, optionally, port) to connect to'
        + ' [e.g. "irc.example.com" or "irc.example.com:6669";'
        + f' default port: {DEFAULT_IRC_PORT:d}]',
        metavar='SERVER',
    )

    parser.add_argument(
        '--irc-server-ssl',
        dest='irc_server_ssl',
        action='store_true',
        help='use SSL to connect to the IRC server',
    )

    return parser


def parse_irc_server_arg(value):
    """Parse a hostname with optional port."""
    fragments = value.split(':', 1)
    if len(fragments) > 1:
        fragments[1] = int(fragments[1])
    return IrcServer(*fragments)
<commit_msg>Clarify `IrcServer` creation from CLI argument<commit_after>"""
syslog2irc.argparser
~~~~~~~~~~~~~~~~~~~~

Command line argument parsing

:Copyright: 2007-2021 <NAME>
:License: MIT, see LICENSE for details.
"""

from argparse import ArgumentParser
import dataclasses

from .irc import IrcServer


DEFAULT_IRC_PORT = IrcServer('').port


def parse_args(args=None):
    """Parse command line arguments."""
    parser = create_arg_parser()
    parsed = parser.parse_args(args)

    irc_server = parsed.irc_server
    if irc_server is not None:
        parsed.irc_server = dataclasses.replace(
            irc_server, ssl=parsed.irc_server_ssl
        )

    return parsed


def create_arg_parser():
    """Prepare the command line arguments parser."""
    parser = ArgumentParser()

    parser.add_argument(
        '--irc-nickname',
        dest='irc_nickname',
        default='syslog',
        help='the IRC nickname the bot should use',
        metavar='NICKNAME',
    )

    parser.add_argument(
        '--irc-realname',
        dest='irc_realname',
        default='syslog2IRC',
        help='the IRC realname the bot should use',
        metavar='REALNAME',
    )

    parser.add_argument(
        '--irc-server',
        dest='irc_server',
        type=parse_irc_server_arg,
        help='IRC server (host and, optionally, port) to connect to'
        + ' [e.g. "irc.example.com" or "irc.example.com:6669";'
        + f' default port: {DEFAULT_IRC_PORT:d}]',
        metavar='SERVER',
    )

    parser.add_argument(
        '--irc-server-ssl',
        dest='irc_server_ssl',
        action='store_true',
        help='use SSL to connect to the IRC server',
    )

    return parser


def parse_irc_server_arg(value):
    """Parse a hostname with optional port."""
    fragments = value.split(':', 1)
    host = fragments[0]
    if len(fragments) > 1:
        port = int(fragments[1])
        return IrcServer(host, port)
    else:
        return IrcServer(host)

{'fraction_non_alphanumeric': 0.1279916753381894, 'fraction_numerical': 0.009365244536940686, 'mean_word_length': 2.714975845410628, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '6511110', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1191, 'n_words': 287}