Skip to content

Commit c51cf08

Browse files
committed
Expose indent and encoding parameters on the cli.
1 parent 47a48f7 commit c51cf08

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

sc2reader/scripts/sc2json.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
import os
5-
import sys
6-
74
import sc2reader
85
from sc2reader.plugins.replay import toJSON
96

7+
108
def main():
11-
factory = sc2reader.factories.SC2Factory()
12-
factory.register_plugin("Replay", toJSON())
9+
import argparse
10+
parser = argparse.ArgumentParser(description="Prints replay data to a json string.")
11+
parser.add_argument('--indent', '-i', type=int, default=None, help="The per-line indent to use when printing a human readable json string")
12+
parser.add_argument('--encoding', '-e', type=str, default='UTF-8', help="The character encoding use..")
13+
parser.add_argument('path', metavar='path', type=str, nargs=1, help="Path to the replay to serialize.")
14+
args = parser.parse_args()
1315

14-
replay_json = factory.load_replay(sys.argv[1])
16+
factory = sc2reader.factories.SC2Factory()
17+
factory.register_plugin("Replay", toJSON(encoding=args.encoding, indent=args.indent))
18+
replay_json = factory.load_replay(args.path[0])
1519
print replay_json
1620

1721
if __name__ == '__main__':

0 commit comments

Comments
 (0)