#!/usr/bin/env python3
from compose_format import ComposeFormat


if __name__ == '__main__':

    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--replace', action='store_const', const=True,
        help='should the original file be replaced?', default=False)
    parser.add_argument(
        '--ignore_changes', action='store_const', const=False,
        help='ignore changes for return code', default=True)
    parser.add_argument('files', nargs=argparse.REMAINDER)
    args = parser.parse_args()
    if len(args.files) == 0:
        import sys
        print('specify at least one file')
        sys.exit(1)

    formatter = ComposeFormat()

    for path in args.files:
        if not formatter.format(path, args.replace):
            if args.replace:
                print('path {} has been changed'.format(path))
            if not args.ignore_changes:
                sys.exit(1)
