diff options
Diffstat (limited to 'src/xpit_/init.py')
| -rw-r--r-- | src/xpit_/init.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/xpit_/init.py b/src/xpit_/init.py new file mode 100644 index 0000000..3663f4f --- /dev/null +++ b/src/xpit_/init.py @@ -0,0 +1,54 @@ +import os +from sys import argv, stdout, stderr +from . import args_helpers, issue_tracker + +help_text = """\ +Usage: xpit init +Options: + -h, --help + Print this help text. +""" + +class Args: + def __init__(self): + pass + + def parse(self) -> bool: + flag_value_map = { + "help|h": 0, + } + res = args_helpers.parse_generic(flag_value_map, argv, 2) + if res is None: + return False + if "help" in res: + stdout.write(help_text) + return False + + return True +args = Args() + +def main() -> int: + if len(argv) < 2: + stdout.write(help_text) + return 1 + + if not args.parse(): + return 1 + + if issue_tracker.find_dir(os.getcwd(), suppress_warning=True) is not None: + stderr.write("xpit already initialized\n") + return 1 + os.mkdir("issue-tracker") + config_file_path = os.path.join("issue-tracker", "_config.ini") + with open(config_file_path, "wb") as f: + f.write(b"""\ +id_format=%Y%m%d_%H%M%S ; `man strftime` for format +allowed_labels=bug,breaking,contributor-friendly,docs,use-case,regression,proposal ; labels that are allowed to be used in issues. (Comma-separated list) +\n""") + stdout.write(f"""\ +Successfully initialized at ./issue-tracker. +Configure in {config_file_path} +""") + + return 0 + |
