<commit_before># -*- coding: utf-8 -*-
import argparse

from ebenezer.xmp import XMPReceiptMetadata

def main():
    parser = argparse.ArgumentParser(description='Easy receipts management.')
    subparsers = parser.add_subparsers(dest='command_name', help='commands')

    # A show command
    show_parser = subparsers.add_parser('show', help='Show receipt\'s metadata')
    show_parser.add_argument('-s', '--sum', action='store_true',
                             help='sum receipts\' price')
    # A set command
    set_parser = subparsers.add_parser('set', help='Set receipt\'s metadata')
    set_parser.add_argument('-p', '--price', action='store', type=float,
                            help='set receipt\'s price')
    set_parser.add_argument('-r', '--retailer', action='store', type=str,
                            help='set receipt\'s retailer')
    # A delete command
    del_parser = subparsers.add_parser('del', help='Delete receipt\'s metadata')
    del_parser.add_argument('-p', '--price', action='store_true',
                            help='delete receipt\'s price')
    del_parser.add_argument('-r', '--retailer', action='store_true',
                            help='delete receipt\'s retailer')

    # A sum command
    sum_parser = subparsers.add_parser('sum', help='Sum receipts\' price')

    # HACK: This can be fixed when http://bugs.python.org/issue9540 will be
    # closed.
    for subparser in (show_parser, set_parser, del_parser, sum_parser):
        subparser.add_argument('receipts', metavar='receipt', nargs='+',
                               help='one or more receipts in a supported '
                                    'format')

    args = parser.parse_args()

    table = []
    price_sum = 0
    max_len_receipt_filename = 0
    max_len_price = 0

    for receipt in args.receipts:
        metadata = XMPReceiptMetadata(receipt)

        if args.command_name == 'del':
            if not args.price and not args.retailer:
                del metadata.price
                del metadata.retailer<commit_msg>Exit with status 1 and a message if trying to use ebenezer over a directory<commit_after># -*- coding: utf-8 -*-
import argparse
import os
import sys

from ebenezer.xmp import XMPReceiptMetadata

def main():
    parser = argparse.ArgumentParser(description='Easy receipts management.')
    subparsers = parser.add_subparsers(dest='command_name', help='commands')

    # A show command
    show_parser = subparsers.add_parser('show', help='Show receipt\'s metadata')
    show_parser.add_argument('-s', '--sum', action='store_true',
                             help='sum receipts\' price')
    # A set command
    set_parser = subparsers.add_parser('set', help='Set receipt\'s metadata')
    set_parser.add_argument('-p', '--price', action='store', type=float,
                            help='set receipt\'s price')
    set_parser.add_argument('-r', '--retailer', action='store', type=str,
                            help='set receipt\'s retailer')
    # A delete command
    del_parser = subparsers.add_parser('del', help='Delete receipt\'s metadata')
    del_parser.add_argument('-p', '--price', action='store_true',
                            help='delete receipt\'s price')
    del_parser.add_argument('-r', '--retailer', action='store_true',
                            help='delete receipt\'s retailer')

    # A sum command
    sum_parser = subparsers.add_parser('sum', help='Sum receipts\' price')

    # HACK: This can be fixed when http://bugs.python.org/issue9540 will be
    # closed.
    for subparser in (show_parser, set_parser, del_parser, sum_parser):
        subparser.add_argument('receipts', metavar='receipt', nargs='+',
                               help='one or more receipts in a supported '
                                    'format')

    args = parser.parse_args()

    table = []
    price_sum = 0
    max_len_receipt_filename = 0
    max_len_price = 0

    for receipt in args.receipts:

        if os.path.isdir(receipt):
            exit_msg = '{} is a directory'.format(receipt)
            sys.exit(exit_msg)

        metadata = XMPReceiptMetadata(receipt)

        if args.command_name == 'del':
            if not args.price and not args.retailer:
                del metadata.price
                del metadata.retailer
{'fraction_non_alphanumeric': 0.12337662337662338, 'fraction_numerical': 0.003942486085343228, 'mean_word_length': 2.423015873015873, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7108799', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1224, 'n_words': 300}