diff --git a/setup.cfg b/setup.cfg index 4fbdef43..9bcece97 100644 --- a/setup.cfg +++ b/setup.cfg @@ -55,9 +55,14 @@ python_requires = >= 3.8 [options.packages.find] where = src +[options.extras_require] +full = + # matplotlib + [options.entry_points] console_scripts = duct = con_duct.__main__:main + con-duct = con_duct.suite:main [mypy] allow_incomplete_defs = False diff --git a/src/con_duct/suite.py b/src/con_duct/suite.py new file mode 100644 index 00000000..71457633 --- /dev/null +++ b/src/con_duct/suite.py @@ -0,0 +1,40 @@ +import argparse +import json +from pprint import pprint + + +def pprint_json(args): + """ + Prints the contents of a JSON file using pprint. + """ + try: + with open(args.file_path, "r") as file: + data = json.load(file) + pprint(data) + + except FileNotFoundError: + print(f"File not found: {args.file_path}") + except json.JSONDecodeError as e: + print(f"Error decoding JSON: {e}") + + +def main(): + parser = argparse.ArgumentParser( + prog="con-duct", + description="A command-line tool for managing various tasks.", + usage="con-duct [options]", + ) + subparsers = parser.add_subparsers(dest="command", help="Available subcommands") + subparsers.required = True # Makes subcommands required + + # Subcommand: pp + parser_pp = subparsers.add_parser("pp", help="Pretty print a log") + parser_pp.add_argument("file_path", help="File to pretty print") + parser_pp.set_defaults(func=pprint_json) + + args = parser.parse_args() + + if args.command is None: + parser.print_help() + else: + args.func(args)