changeset 5:d5198c7ec54d

Add --uncurl option.
author David Barts <n5jrn@me.com>
date Thu, 26 Dec 2019 20:24:32 -0800
parents 7a83e82e65a6
children da3fb2312c88
files curlyq
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/curlyq	Thu Dec 26 20:04:04 2019 -0800
+++ b/curlyq	Thu Dec 26 20:24:32 2019 -0800
@@ -57,13 +57,20 @@
         curler.feed()
         output_fp.write(ws.getvalue())
 
+def do_uncurl():
+    global input_fp, output_fp
+    with Workspace(input_fp.read()) as ws:
+        uncurl(ws)
+        output_fp.write(ws.getvalue())
+
 # M a i n   P r o g r a m
 
 # Parse arguments
-parser = argparse.ArgumentParser(description='Source code character checker.', prog=MYNAME)
+parser = argparse.ArgumentParser(description='Make straight quotes curly.', prog=MYNAME)
 group = parser.add_mutually_exclusive_group()
 group.add_argument("--flowed", action="store_true", help="Input is flowed text.")
 group.add_argument("--html", action="store_true", help="Input is HTML.")
+group.add_argument("--uncurl", action="store_true", help="Uncurl quotes instead of curling them.")
 parser.add_argument("--force", action="store_true", help="Force all quotes to straight ones first.")
 parser.add_argument("--icoding", default="UTF-8", help="Input encoding.")
 parser.add_argument("--inplace", action="store_true", help="Edit file in-place.")
@@ -92,7 +99,7 @@
     if args.input and (not args.output) and args.inplace:
         args.output = args.input
         args.input += "~"
-        os.rename(args.input, args.output)
+        os.rename(args.output, args.input)
     if args.input:
         input_fp = open(args.input, "r", encoding=args.icoding)
     else:
@@ -110,5 +117,7 @@
     flowed()
 elif args.html:
     html()
+elif args.uncurl:
+    do_uncurl()
 else:
     normal()