mirror of https://github.com/Textualize/rich.git
Add stdin support to rich.json
This commit is contained in:
parent
bd34e0a1ef
commit
8370e69549
10
rich/json.py
10
rich/json.py
|
@ -54,6 +54,7 @@ if __name__ == "__main__":
|
|||
"path",
|
||||
metavar="PATH",
|
||||
help="path to file, or - for stdin",
|
||||
nargs='?',
|
||||
)
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
|
@ -69,10 +70,13 @@ if __name__ == "__main__":
|
|||
|
||||
console = Console()
|
||||
error_console = Console(stderr=True)
|
||||
|
||||
|
||||
try:
|
||||
with open(args.path, "rt") as json_file:
|
||||
json_data = json_file.read()
|
||||
if args.path is None:
|
||||
json_data = sys.stdin.read()
|
||||
else:
|
||||
with open(args.path, "rt") as json_file:
|
||||
json_data = json_file.read()
|
||||
except Exception as error:
|
||||
error_console.print(f"Unable to read {args.path!r}; {error}")
|
||||
sys.exit(-1)
|
||||
|
|
Loading…
Reference in New Issue