<commit_before>#!/usr/bin/env python
'''
Python 2.x / 3.x

clapp.py

v0.4.2

A library for building command line applications
'''

from __future__ import print_function
import sys
from os import path

__version__ = '0.4.2'
__build__ = '2'
__author__ = '<NAME>. <<EMAIL>>'


def _null_func(context):
    """Represents a None for a function"""
    pass


class App(object):
    """The starting point for a command line application"""
    def __init__(self, name='', version='', about='', main=_null_func):
        """Initializes a new version of the App class
        PARAMS:
            name: A string representing the name of the application
            version: A string representing the version of the application
            about: A string that displays what the application briefly doesn
            main: A function which accepts a dict() and the starting point of the app
                  will be called after all command line argumetns have been processed
        """
        self._name = name
        self._version = version
        self._args_map = dict()
        self._raw_args = sys.argv
        self._about = about
        self._has_main = False
        if main != _null_func:
            self._has_main = True
        self._main = main
        self._context = dict()
        self._subcmds_map = dict()
        self._subcmds = []
        self._req_opts = []
        self._flags = []
        self._req_pos_args = []
        self._pos_args = []
        self._opts = []

    def start(self):
        """Called when the user wants to start processing command line arguments
        and start his main(context) function
        RETURN: Returns whatever your main(context) returns in order to allow
                sys.exit(app.start())
        """
        # Add a help command line argument if needed (i.e. -h and --help)
        self._add_help()
        # Add a version command line argument if needed (i.e. -v and --version)
        self._add_version()

        self._context['raw_args'] = sys.argv
        self._do_args(sys.argv[1:])

        if self._has_main:
            return self._main(self._context)
<commit_msg>start() now returns the context dict() if no main is defined<commit_after>#!/usr/bin/env python
'''
Python 2.x / 3.x

clapp.py

v0.4.2

A library for building command line applications
'''

from __future__ import print_function
import sys
from os import path

__version__ = '0.4.3'
__build__ = '1'
__author__ = '<NAME>. <<EMAIL>>'


def _null_func(context):
    """Represents a None for a function"""
    pass


class App(object):
    """The starting point for a command line application"""
    def __init__(self, name='', version='', about='', main=_null_func):
        """Initializes a new version of the App class
        PARAMS:
            name: A string representing the name of the application
            version: A string representing the version of the application
            about: A string that displays what the application briefly doesn
            main: A function which accepts a dict() and the starting point of the app
                  will be called after all command line argumetns have been processed
        """
        self._name = name
        self._version = version
        self._args_map = dict()
        self._raw_args = sys.argv
        self._about = about
        self._has_main = False
        if main != _null_func:
            self._has_main = True
        self._main = main
        self._context = dict()
        self._subcmds_map = dict()
        self._subcmds = []
        self._req_opts = []
        self._flags = []
        self._req_pos_args = []
        self._pos_args = []
        self._opts = []

    def start(self):
        """Called when the user wants to start processing command line arguments
        and start his main(context) function
        RETURN: Returns whatever your main(context) returns in order to allow
                sys.exit(app.start())
        """
        # Add a help command line argument if needed (i.e. -h and --help)
        self._add_help()
        # Add a version command line argument if needed (i.e. -v and --version)
        self._add_version()

        self._context['raw_args'] = sys.argv
        self._do_args(sys.argv[1:])

        if self._has_main:
            return self._main(self._context)
        return self._context

{'fraction_non_alphanumeric': 0.09428307976025818, 'fraction_numerical': 0.004610419548178884, 'mean_word_length': 2.18108504398827, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4959773', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1182, 'n_words': 430}