<commit_before>#!/usr/bin/python3
import sys
import argparse
import os
import io
import configparser

# TODO
# Check if INI syntax is OK
# Colored or formated output... better readable anyways

desc = "Cool Command-Line Cheatsheets"
extension = ".ini"
cheatsheets = {}
configDir = "./config/"
cfgParser = configparser.ConfigParser()
argParser = argparse.ArgumentParser(description=desc)

#Command Line Arguments
group = argParser.add_mutually_exclusive_group()
group.add_argument("-l", "--inline", action="store_true", help="Output each line, this is default")
group.add_argument("-b", "--breakline", action="store_true", help="Output break line")
argParser.add_argument("cheatsheet", help="The cheatsheet you want to see")

def printInline():
    width = 10

    for key in cfgParser['cheats']:
        if len(key) > width:
            width = len(key)

    for key in cfgParser['cheats']:
        output = "{0:<{1}} {2}".format(key, width, cfgParser['cheats'][key])
        print(output)

def printBreakline():
    for key in cfgParser['cheats']:
        output = "{0} \n {1}".format(key, cfgParser['cheats'][key])
        print(output)

def indexCheatsheets():
    tmpParser = configparser.ConfigParser()
    for filename in os.listdir(configDir):
        if filename.endswith(extension):
            tmpParser.read(configDir + filename)
            cheatsheets[tmpParser['main']['name']] = filename

def main():
    args = argParser.parse_args()

    indexCheatsheets()

    if args.cheatsheet in cheatsheets.keys():
        cfgParser.read(configDir + cheatsheets[args.cheatsheet])

        if args.breakline:
            printBreakline()
        else:
            printInline()

        exit(0)
    else:
        print('Cheatsheet \"'+ args.cheatsheet +'\" not available')
        exit(1)

if __name__ == "__main__":
    main()<commit_msg>Added handling of faulty INI files... not sure if it should throw an error though.<commit_after>#!/usr/bin/python3
import sys
import argparse
import os
import io
import configparser

desc = "Cool Command-Line Cheatsheets"
extension = ".ini"
cheatsheets = {}
configDir = "./config/"
cfgParser = configparser.ConfigParser()
argParser = argparse.ArgumentParser(description=desc)

#Command Line Arguments
group = argParser.add_mutually_exclusive_group()
group.add_argument("-l", "--inline", action="store_true", help="Output each line, this is default")
group.add_argument("-b", "--breakline", action="store_true", help="Output break line")
argParser.add_argument("cheatsheet", help="The cheatsheet you want to see")

def printInline():

    width = 10

    for key in cfgParser['cheats']:
        if len(key) > width:
            width = len(key)

    for key in cfgParser['cheats']:
        output = "{0:<{1}} {2}".format(key, width, cfgParser['cheats'][key])
        print(output)

def printBreakline():

    for key in cfgParser['cheats']:
        output = "{0} \n {1}".format(key, cfgParser['cheats'][key])
        print(output)

def indexCheatsheets():

    tmpParser = configparser.ConfigParser()

    for filename in os.listdir(configDir):
        try:
            if filename.endswith(extension):
                tmpParser.read(configDir + filename)
                cheatsheets[tmpParser['main']['name']] = filename
        except configparser.MissingSectionHeaderError as exception:
            print(exception)

def main():

    args = argParser.parse_args()

    indexCheatsheets()

    if args.cheatsheet in cheatsheets.keys():
        cfgParser.read(configDir + cheatsheets[args.cheatsheet])

        if args.breakline:
            printBreakline()
        else:
            printInline()

        exit(0)

    else:
        print('Cheatsheet \"'+ args.cheatsheet +'\" not available')
        exit(1)

if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.1320854205114685, 'fraction_numerical': 0.005272871078302136, 'mean_word_length': 3.287005649717514, 'pattern_counts': {'":': 2, '<': 5, '<?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': '27923', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1135, 'n_words': 287}