(pth=None, out=sys.stdout)
| 186 | |
| 187 | |
| 188 | def main(pth=None, out=sys.stdout): |
| 189 | if "--environment-only" in sys.argv: |
| 190 | print(json.dumps(get_environment()), file=out) |
| 191 | return sys.exit(0) |
| 192 | |
| 193 | if pth is None: |
| 194 | pth = sys.argv[1] |
| 195 | |
| 196 | if pth != "-": |
| 197 | encoding = get_encoding(pth) |
| 198 | |
| 199 | with open(pth, "rb") as fd: |
| 200 | source_code = fd.read() |
| 201 | else: |
| 202 | encoding = sys.getdefaultencoding() |
| 203 | source_code = sys.stdin.read() |
| 204 | |
| 205 | try: |
| 206 | src_dump = collect(source_code=source_code, encoding=encoding) |
| 207 | print(json.dumps(src_dump), file=out) |
| 208 | except SyntaxError: |
| 209 | traceback.print_exc(file=sys.stderr) |
| 210 | sys.exit(1) |
| 211 | except Exception: |
| 212 | print("Error parsing source code for file: " + pth, file=sys.stderr) |
| 213 | raise |
| 214 | |
| 215 | |
| 216 | if __name__ == "__main__": |
no test coverage detected