Skip to content

Commit 30d04c4

Browse files
adding example option for cli
1 parent 91da525 commit 30d04c4

File tree

4 files changed

+69
-16
lines changed

4 files changed

+69
-16
lines changed

json_explorer/cli.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import webbrowser
66
from http.server import BaseHTTPRequestHandler, HTTPServer
77

8-
from .explore import TripleCounter
8+
from .explore import THIS_DIR, TripleCounter
99

1010

1111
def start_browser(server_ready_event, url):
@@ -21,19 +21,43 @@ def jsonl_iterator(filename):
2121

2222
def main():
2323
parser = argparse.ArgumentParser(
24-
prog="ProgramName",
25-
description="What the program does",
26-
epilog="Text at the bottom of help",
24+
description="visualize the structure and type of a group of JSONs",
2725
)
2826
parser.add_argument(
2927
"filename",
3028
help="filename of a file in JSON Lines format",
29+
nargs="?",
30+
default=None,
31+
)
32+
parser.add_argument(
33+
"--example",
34+
help="run with test data",
35+
action="store_true",
36+
)
37+
parser.add_argument(
38+
"-p",
39+
"--port",
40+
default=8001,
41+
type=int,
42+
help="port for server (default 8001)",
43+
)
44+
parser.add_argument(
45+
"-n",
46+
"--no-serve",
47+
help="write HTML to stdout instead of opening browser",
48+
action="store_true",
3149
)
32-
parser.add_argument("-p", "--port", default=8001, type=int, help="port for server (default 8001)")
33-
parser.add_argument("-n", "--no-serve", help="write HTML to stdout instead of serving", action="store_true")
3450
args = parser.parse_args()
3551

36-
counter = TripleCounter.from_objects(jsonl_iterator(args.filename))
52+
filename = args.filename
53+
if not args.example and not args.filename:
54+
parser.error("filename is required (unless --example is given)")
55+
elif args.example and args.filename:
56+
parser.error("can't pass both filename and --example")
57+
elif args.example:
58+
filename = THIS_DIR / "example1.jsonl"
59+
60+
counter = TripleCounter.from_objects(jsonl_iterator(filename))
3761
response_text = counter.html()
3862

3963
if args.no_serve:

0 commit comments

Comments
 (0)