<commit_before># -*- coding: utf-8 -*-
# Copyright (c) 2013-2016, <NAME>

# Released under the Simplified BSD license
# (see LICENSE file for details).

"""
The command-line interface for `shcol`.
"""

import argparse
import sys
import traceback

from . import __version__, config, helpers, highlevel

__all__ = ['main']

class ArgumentParser(argparse.ArgumentParser):
    """
    Implementation for generating help text and command-line parsing.
    """
    def __init__(
        self, prog_name, version, stdin=config.INPUT_STREAM,
        stdout=config.TERMINAL_STREAM, stderr=config.ERROR_STREAM
    ):
        """
        Initialize the parser.

        `prog_name` defines the program name used when displaying information.

        `version` should be a string containing the program's version.

        `stdin`, `stdout` and `stderr` are the streams to use. They should be
        file-like objects defining at least a `.read()` and a `.write()` method.
        """
        self.version_string = '{} {}'.format(prog_name, version)
        argparse.ArgumentParser.__init__(
            self, prog=prog_name, formatter_class=argparse.RawTextHelpFormatter,
            description='Generate columnized output for given string items.\n\n'
            'Columize and sort:\n'
            '%(prog)s -S foo bar baz\n\n'
            'Columnize command output on Linux (Debian):\n'
            '%(prog)s -S -c0 < /proc/modules\n'
            'dpkg --get-selections \'python3*\' | %(prog)s -c0 -s4\n\n'
            'Columnize process names on Windows PowerShell:\n'
            '(ps).name | %(prog)s -U'
        )
        self.stdin = stdin
        self.stdout = stdout
        self.stderr = stderr
        self.init_arguments()

    def print_message(self, message, stream=None):
        """
        Print `message` to `stream`.

        If `stream` is `sys.stdout` or `sys.stderr` then it is translated to its
        corresponding instance variable (`self.stdout` or `self.stderr`).

        This technique makes it possible to control the output streams of some
        internal methods defined by the superclass. Most of them do not support
        setting alternative streams directly. Instead, they invoke methods that
        are based on `_print_message()`. By redefining that method, which does
        expect the stream to be used as a parameter, the new implementation is
        able to map those stream references to alternative streams.

        Note that the actual work is done by `_print_message`. The "public"
        version of it (`print_message`) is used a thin wrapper around it.
        """
        self._print_message(message, stream)

    def _print_message(self, message, stream):
        """
        Redefined internal method called by the superclass. See docstring of
        `print_message()` for details.
        """
        if stream is sys.stdout:
            stream = self.stdout
        elif stream is sys.stderr:
            stream = self.stderr
        argparse.ArgumentParser._print_message(self, message, file=stream)

    def init_arguments(self):
        """
        Argument names and the whole CLI-syntax are defined by this method.
        """
        self.add_argument(
            'items', nargs='*', metavar='item',
            help='an item to columnize\n'
                 '(read from stdin if item arguments are not present)'
        )
        self.add_argument(
            '-s', '--spacing', metavar='N', type=helpers.num,
            default=config.SPACING,
            help='number of blanks between two columns (default: {})'
                 .format(config.SPACING)
        )
        self.add_argument(
            '-w', '--width', metavar='N', type=helpers.num,
            help='maximal amount of characters per line\n'
                 '(use terminal width by default)'
        )
        self.add_argument(
            '-e', '--extra-sep', metavar='C', type=str,
            default=config.EXTRA_SEP,
            help='additional character between columns (default: {})'
                 .format(config.EXTRA_SEP)
        )
        self.add_argument(
            '-c', '--column', metavar='N', type=helpers.num, dest='column',<commit_msg>Use `super()` in `_print_message()`.<commit_after># -*- coding: utf-8 -*-
# Copyright (c) 2013-2016, <NAME>

# Released under the Simplified BSD license
# (see LICENSE file for details).

"""
The command-line interface for `shcol`.
"""

import argparse
import sys
import traceback

from . import __version__, config, helpers, highlevel

__all__ = ['main']

class ArgumentParser(argparse.ArgumentParser):
    """
    Implementation for generating help text and command-line parsing.
    """
    def __init__(
        self, prog_name, version, stdin=config.INPUT_STREAM,
        stdout=config.TERMINAL_STREAM, stderr=config.ERROR_STREAM
    ):
        """
        Initialize the parser.

        `prog_name` defines the program name used when displaying information.

        `version` should be a string containing the program's version.

        `stdin`, `stdout` and `stderr` are the streams to use. They should be
        file-like objects defining at least a `.read()` and a `.write()` method.
        """
        self.version_string = '{} {}'.format(prog_name, version)
        argparse.ArgumentParser.__init__(
            self, prog=prog_name, formatter_class=argparse.RawTextHelpFormatter,
            description='Generate columnized output for given string items.\n\n'
            'Columize and sort:\n'
            '%(prog)s -S foo bar baz\n\n'
            'Columnize command output on Linux (Debian):\n'
            '%(prog)s -S -c0 < /proc/modules\n'
            'dpkg --get-selections \'python3*\' | %(prog)s -c0 -s4\n\n'
            'Columnize process names on Windows PowerShell:\n'
            '(ps).name | %(prog)s -U'
        )
        self.stdin = stdin
        self.stdout = stdout
        self.stderr = stderr
        self.init_arguments()

    def print_message(self, message, stream=None):
        """
        Print `message` to `stream`.

        If `stream` is `sys.stdout` or `sys.stderr` then it is translated to its
        corresponding instance variable (`self.stdout` or `self.stderr`).

        This technique makes it possible to control the output streams of some
        internal methods defined by the superclass. Most of them do not support
        setting alternative streams directly. Instead, they invoke methods that
        are based on `_print_message()`. By redefining that method, which does
        expect the stream to be used as a parameter, the new implementation is
        able to map those stream references to alternative streams.

        Note that the actual work is done by `_print_message`. The "public"
        version of it (`print_message`) is used a thin wrapper around it.
        """
        self._print_message(message, stream)

    def _print_message(self, message, stream):
        """
        Redefined internal method called by the superclass. See docstring of
        `print_message()` for details.
        """
        if stream is sys.stdout:
            stream = self.stdout
        elif stream is sys.stderr:
            stream = self.stderr
        super(type(self), self)._print_message(message, file=stream)

    def init_arguments(self):
        """
        Argument names and the whole CLI-syntax are defined by this method.
        """
        self.add_argument(
            'items', nargs='*', metavar='item',
            help='an item to columnize\n'
                 '(read from stdin if item arguments are not present)'
        )
        self.add_argument(
            '-s', '--spacing', metavar='N', type=helpers.num,
            default=config.SPACING,
            help='number of blanks between two columns (default: {})'
                 .format(config.SPACING)
        )
        self.add_argument(
            '-w', '--width', metavar='N', type=helpers.num,
            help='maximal amount of characters per line\n'
                 '(use terminal width by default)'
        )
        self.add_argument(
            '-e', '--extra-sep', metavar='C', type=str,
            default=config.EXTRA_SEP,
            help='additional character between columns (default: {})'
                 .format(config.EXTRA_SEP)
        )
        self.add_argument(
            '-c', '--column', metavar='N', type=helpers.num, dest='column',
{'fraction_non_alphanumeric': 0.10684116597263534, 'fraction_numerical': 0.003093396787626413, 'mean_word_length': 2.2405551272166537, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '563132', 'n_tokens_mistral': 2348, 'n_tokens_neox': 2272, 'n_words': 758}