Skip to content

Instantly share code, notes, and snippets.

@kiyoon
Last active January 30, 2024 13:42
Show Gist options
  • Save kiyoon/bd5334f03136bad752b358f71fc00eca to your computer and use it in GitHub Desktop.
Save kiyoon/bd5334f03136bad752b358f71fc00eca to your computer and use it in GitHub Desktop.
import argparse
from rich_argparse import ArgumentDefaultsRichHelpFormatter
def get_parser():
parser = argparse.ArgumentParser(
description="Example of argparse usage, with default values printed in help.",
formatter_class=ArgumentDefaultsRichHelpFormatter,
)
parser.add_argument(
"--example_string",
default="example",
help="path to config file",
)
parser.add_argument(
"--example_bool",
action="store_true",
help="Save bounding box visualisation.",
)
parser.add_argument(
"--example_list",
nargs="+",
default=[1, 2, 3],
help="List of integers",
)
parser.add_argument(
"--example_choices",
choices=["a", "b", "c"],
default="a",
help="Choices",
)
return parser
def main():
parser = get_parser()
args = parser.parse_args()
# if (
# bool(args.video_input) + bool(args.images_input_dir) + bool(args.videos_input_dir)
# != 1
# ):
# parser.error(
# "--video_input, --video_input_dir and --images_input_dir can't come together and only one must be specified."
# )
def save_args(args: argparse.Namespace):
# Save args to json
import json
with open("args.json", "w") as f:
json.dump(args.__dict__, f, ensure_ascii=False, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment