Add contentreplace helptext.

This commit is contained in:
voussoir 2021-11-08 11:39:17 -08:00
parent a745e1ad30
commit 5aab0c2b2a
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -1,9 +1,43 @@
'''
contentreplace - find-and-replace en masse
==========================================
> contentreplace filename_glob replace_from replace_to <flags>
filename_glob:
A glob pattern that targets the files of interest.
replace_from:
String to be replaced.
replace_to:
String with which to replace.
flags:
--recurse:
If provided, we will recurse into subdirectories and look for glob matches
there too. If not provided, only files in the cwd are affected.
--regex:
If provided, the given replace_from, replace_to will be treated as regex
strings. If not provided, we use regular str.replace
--clip_prompt:
If you want to do contentreplace with unicode that is difficult to enter
into your terminal, or multi-line strings that don't work as command line
arguments, this option might help you. The program will wait for you to put
the text of interest into your clipboard and press Enter.
--yes:
If provided, replacements will occur automatically without prompting.
'''
import argparse import argparse
import codecs import codecs
import pyperclip import pyperclip
import re import re
import sys import sys
from voussoirkit import betterhelp
from voussoirkit import interactive from voussoirkit import interactive
from voussoirkit import pathclass from voussoirkit import pathclass
from voussoirkit import pipeable from voussoirkit import pipeable
@ -77,14 +111,13 @@ def main(argv):
parser.add_argument('filename_glob') parser.add_argument('filename_glob')
parser.add_argument('replace_from') parser.add_argument('replace_from')
parser.add_argument('replace_to') parser.add_argument('replace_to')
parser.add_argument('-y', '--yes', dest='autoyes', action='store_true', help='accept results without confirming') parser.add_argument('--yes', dest='autoyes', action='store_true')
parser.add_argument('--recurse', action='store_true') parser.add_argument('--recurse', action='store_true')
parser.add_argument('--regex', dest='do_regex', action='store_true') parser.add_argument('--regex', dest='do_regex', action='store_true')
parser.add_argument('--clip_prompt', '--clip-prompt', action='store_true') parser.add_argument('--clip_prompt', '--clip-prompt', action='store_true')
parser.set_defaults(func=contentreplace_argparse) parser.set_defaults(func=contentreplace_argparse)
args = parser.parse_args(argv) return betterhelp.single_main(argv, parser, __doc__)
return args.func(args)
if __name__ == '__main__': if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:])) raise SystemExit(main(sys.argv[1:]))