Skip to content

Commit

Permalink
adding example option for cli
Browse files Browse the repository at this point in the history
  • Loading branch information
stringertheory committed Jun 8, 2023
1 parent 91da525 commit 30d04c4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 16 deletions.
38 changes: 31 additions & 7 deletions json_explorer/cli.py
Expand Up @@ -5,7 +5,7 @@
import webbrowser
from http.server import BaseHTTPRequestHandler, HTTPServer

from .explore import TripleCounter
from .explore import THIS_DIR, TripleCounter


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

def main():
parser = argparse.ArgumentParser(
prog="ProgramName",
description="What the program does",
epilog="Text at the bottom of help",
description="visualize the structure and type of a group of JSONs",
)
parser.add_argument(
"filename",
help="filename of a file in JSON Lines format",
nargs="?",
default=None,
)
parser.add_argument(
"--example",
help="run with test data",
action="store_true",
)
parser.add_argument(
"-p",
"--port",
default=8001,
type=int,
help="port for server (default 8001)",
)
parser.add_argument(
"-n",
"--no-serve",
help="write HTML to stdout instead of opening browser",
action="store_true",
)
parser.add_argument("-p", "--port", default=8001, type=int, help="port for server (default 8001)")
parser.add_argument("-n", "--no-serve", help="write HTML to stdout instead of serving", action="store_true")
args = parser.parse_args()

counter = TripleCounter.from_objects(jsonl_iterator(args.filename))
filename = args.filename
if not args.example and not args.filename:
parser.error("filename is required (unless --example is given)")
elif args.example and args.filename:
parser.error("can't pass both filename and --example")
elif args.example:
filename = THIS_DIR / "example1.jsonl"

counter = TripleCounter.from_objects(jsonl_iterator(filename))
response_text = counter.html()

if args.no_serve:
Expand Down

0 comments on commit 30d04c4

Please sign in to comment.