summaryrefslogtreecommitdiffstats
path: root/g2h/cli.py
diff options
context:
space:
mode:
authorChristoph Schlosser <christoph@linux.com>2025-09-19 19:21:11 +0200
committerChristoph Schlosser <christoph@linux.com>2025-09-19 19:21:11 +0200
commita3324b7e71ec48daab81981e7d85967a590d4f79 (patch)
treedef4a8d901d9a56047a0e63f5f3d93803c93ee87 /g2h/cli.py
parentbd403e6ab18d5cc7818e86d43c3ca0b15c5e53a1 (diff)
downloadgit2hugo-a3324b7e71ec48daab81981e7d85967a590d4f79.tar.gz
g2h: Add utility script
Also move the sources into the more conventional src/g2h dir
Diffstat (limited to 'g2h/cli.py')
-rw-r--r--g2h/cli.py42
1 files changed, 0 insertions, 42 deletions
diff --git a/g2h/cli.py b/g2h/cli.py
deleted file mode 100644
index 3f60b82..0000000
--- a/g2h/cli.py
+++ /dev/null
@@ -1,42 +0,0 @@
-import argparse
-import os
-
-from .git import Git
-from .page_factory import PageFactory
-
-def parse_args():
- parser = argparse.ArgumentParser(
- prog='g2h',
- description='Convert a git repository into markdown files Hugo can understand.')
- # TODO: Defaults for these two values should be $PWD.
- parser.add_argument('repo_path', help='Path to the root of git repository')
- parser.add_argument('out_dir', help='Path to where the generated files should be stored')
- parser.add_argument('--name', help='Name of the project. Default: directory name of repo')
- parser.add_argument('--content-subdir', help='Subdir(s) where the page will be served from. Default: None', default='')
-
- return parser.parse_args()
-
-def main():
- args = parse_args()
- git = Git(args.repo_path)
-
- branches = sorted(git.get_branches(), key=lambda b: b.commit.committed_date, reverse=True)
- commits = git.get_commits()
- head = git.get_head()
- # TODO: Fix this for repo_path=(.|~)
- project_name = args.name if args.name is not None else os.path.basename(args.repo_path)
- tags = sorted(git.get_tags(), key=lambda t: t.commit.committed_date, reverse=True)
-
- factory = PageFactory(args.out_dir, project_name, args.content_subdir)
- factory.new_overview(branches, tags, head).render()
- factory.new_log(commits, branches, tags, head).render()
- for commit in commits:
- factory.new_commit(commit).render()
- tree = factory.new_tree(commit, '', git.get_repo())
- for tree_page in tree.build_pages(factory):
- tree_page.render()
- for file in tree_page.get_files():
- factory.new_file(commit, file).render()
-
-if __name__ == '__main__':
- main()