A regex file renamer/mover
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

simplifying the CLI usage a bit

Summer 37cc15bb d9f1ae45

+14 -6
+13 -5
multimv/__init__.py
··· 20 20 21 21 @main.command() 22 22 @click.option("-g", "--global", "global_", is_flag=True) 23 - @click.option("--eval", "eval_", is_flag=True) 23 + @click.option("--fstring", "fstring", is_flag=True) 24 24 @click.argument("pattern") 25 25 @click.argument("replacement") 26 26 @click.argument("files", nargs=-1, type=click.Path()) 27 27 @click.pass_context 28 - def re(ctx, pattern, replacement, files, eval_, global_): 29 - if eval_: 30 - repl = replacement 28 + def re(ctx, pattern, replacement, files, fstring, global_): 29 + if fstring: 30 + # This code is too messy 31 + if '"""' in replacement and '"""' in replacement: 32 + raise Exception("Replacement can't have both ''' and \"\"\"") 33 + 34 + evalstr = "f'''" + replacement + "'''" 35 + if "'''" in replacement: 36 + evalstr = 'f"""' + replacement + '"""' 37 + 31 38 def replacement(match): 32 39 local = { 33 40 "m0": match.group(0), 34 41 **{f"m{i}": g for i, g in enumerate(match.groups(), 1)}, 35 42 **match.groupdict(), 43 + "m": match, 36 44 } 37 - return str(eval(repl, {}, local)) 45 + return str(eval(evalstr, {}, local)) 38 46 39 47 count = 0 if global_ else 1 40 48 regex = compile(pattern)
+1 -1
pyproject.toml
··· 1 1 [tool.poetry] 2 2 name = "multimv" 3 - version = "0.5.0" 3 + version = "0.6.0" 4 4 description = "Multi mv via fixed string / regex / bash pattern substitutions" 5 5 authors = ["Summer"] 6 6 license = "MIT"