Last active
May 19, 2023 13:35
-
-
Save agateau-gg/0c733a9ab1fe7e593a935ee15e1e3665 to your computer and use it in GitHub Desktop.
An interactive version of scriv
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
#!/usr/bin/env python3 | |
""" | |
Interfactive version of scriv | |
""" | |
import argparse | |
import sys | |
from typing import List, Optional | |
from scriv.changelog import Fragment | |
from scriv.gitinfo import git_edit | |
from scriv.scriv import Scriv, _new_fragment_path | |
def select_category(categories: List[str]) -> Optional[str]: | |
for idx, category in enumerate(categories, start=1): | |
print(f"{idx}: {category}") | |
print() | |
print("Select a category: ", end="") | |
answer = input() | |
try: | |
idx = int(answer) - 1 | |
except ValueError: | |
print(f"Invalid value: not a number") | |
return None | |
if idx < 0 or idx >= len(categories): | |
print(f"Invalid value: not a valid category number") | |
return None | |
return categories[idx] | |
def main(): | |
parser = argparse.ArgumentParser( | |
formatter_class=argparse.RawDescriptionHelpFormatter, | |
description=__doc__) | |
args = parser.parse_args() | |
scriv = Scriv() | |
categories = scriv.config.categories | |
category = select_category(categories) | |
if category is None: | |
return 1 | |
# TODO generate from a template | |
content = f"### {category}\n\n- " | |
frag = Fragment( | |
format=scriv.config.format, | |
path=_new_fragment_path(scriv.config), | |
content=content | |
) | |
frag.write() | |
git_edit(frag.path) | |
return 0 | |
if __name__ == "__main__": | |
sys.exit(main()) | |
# vi: ts=4 sw=4 et |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment