Skip to content

Commit

Permalink
Create structure for full con-duct suite
Browse files Browse the repository at this point in the history
Fixes con#122
  • Loading branch information
asmacdo committed Aug 22, 2024
1 parent c2f1187 commit 3d9ec18
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions src/con_duct/suite.py
Original file line number Diff line number Diff line change
@@ -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 <command> [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)

0 comments on commit 3d9ec18

Please sign in to comment.