-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create structure for full con-duct suite
Fixes con#122
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |