Add --dryrun and --funky modes. closes #4, closes #5

This commit is contained in:
Kjistóf 2017-08-23 23:16:50 +02:00 committed by Kristóf Tóth
parent 347affa0c5
commit 57d0ab4650
1 changed files with 14 additions and 1 deletions

View File

@ -61,6 +61,11 @@ if __name__ == '__main__':
help='Specify a special character to disallow (it will removed).')
parser.add_argument('--whitelist', '-w', type=str,
help='Overwrite default whitelist (format: whitespace separated string).')
mgroup = parser.add_mutually_exclusive_group()
mgroup.add_argument('--dryrun', '-n', action='store_true',
help='Do not touch anything, just tell me what would change!')
mgroup.add_argument('--funky', '-f', action='store_true',
help='List filenames with special characters')
parser.add_argument('files', type=str, nargs='+',
help='File(s) to normalise the name of (relative or absolute path).')
args = parser.parse_args()
@ -78,5 +83,13 @@ if __name__ == '__main__':
if args.allow: whitelist = whitelist.union(set(args.allow))
if args.disallow: whitelist = whitelist.difference(set(args.disallow))
# define operations
listchanges = lambda a, b: print('{}{} --> {}'.format(a, ' '*(60-len(a)), b))
listfunky = lambda a, b: print(b)
normalisename(rename, args.separator, whitelist).normalise(args.files)
operation = rename
if args.dryrun: operation = listchanges
elif args.funky: operation = listfunky
normalisename(operation, args.separator, whitelist).normalise(args.files)