Skip to content

Commit

Permalink
Added a way to reformat files from the command line. (#147)
Browse files Browse the repository at this point in the history
* Added a way to reformat files from the command line.

* Updated command line flags.

* Made it a function.

* whoops

* Pedantic.

* Added newline to end.

* Fixed.
  • Loading branch information
rahularya50 authored Apr 10, 2019
1 parent 1993398 commit a035b4d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions editor/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@

import local_server
import log
from formatter import prettify


def reformat_files(src, dest=None):
if dest is None:
dest = src
with open(src) as src:
formatted = prettify([src.read()])
with open(dest, "w") as dest:
dest.write(formatted + "\n")
exit()


parser = argparse.ArgumentParser(description="CS61A Scheme Editor - Spring 2019")

parser.add_argument("-f", "--files",
type=argparse.FileType('r+'),
help="Scheme files to test",
metavar="FILE",
nargs='*')
parser.add_argument("-nb", "--nobrowser",
help="Do not open a new browser window.",
Expand All @@ -20,8 +34,17 @@
type=int,
default=31415,
help="Choose the port to access the editor")
parser.add_argument("-r", "--reformat",
type=str,
nargs="*",
help="Reformats file and writes to second argument, if exists, or in-place, otherwise..",
metavar='FILE')
args = parser.parse_args()

if args.reformat is not None:
reformat_files(*args.reformat)


log.logger.dotted = args.dotted

configs = [f for f in os.listdir(os.curdir) if f.endswith(".ok")]
Expand Down

0 comments on commit a035b4d

Please sign in to comment.