From 0d696114b25040b6f6dc5ac20926e25cdd0f3eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sun, 2 Sep 2018 17:01:05 +0200 Subject: [PATCH] Implement --check option --- cli.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/cli.py b/cli.py index 0bdb4b5..4740216 100755 --- a/cli.py +++ b/cli.py @@ -35,6 +35,11 @@ if __name__ == '__main__': '--funky', '-f', action='store_true', help='List filenames with special characters' ) + mgroup.add_argument( + '--check', '-c', action='store_true', + help='Check whether a name is normalised or not' + ) + parser.add_argument( 'files', type=str, nargs='+', help='File(s) to normalise the name of (relative or absolute path).' @@ -59,14 +64,24 @@ if __name__ == '__main__': whitelist = whitelist.difference(set(args.disallow)) # define operations - listchanges = lambda a, b: print('{}{} --> {}'.format(a, ' '*(60-len(a)), b)) - listfunky = lambda a, b: print(a) + def listchanges(before, after): + print(f'{after}{" "*(60-len(after))} --> {before}') + + def listfunky(before, _): + print(before) + + def checkname(before, after): + if before != after: + sys.exit(1) + sys.exit(0) operation = rename if args.dryrun: operation = listchanges elif args.funky: operation = listfunky + elif args.check: + operation = checkname # do what needs to be done Normalisename(operation, args.separator, whitelist)(args.files)