summaryrefslogtreecommitdiffstats
path: root/g2h/cli.py
blob: fc14582a22679b263e175a1f24527cf1855cd953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import argparse
import os

from .git import Git
from .gen import Generator

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')

    return parser.parse_args()

def main():
    args = parse_args()
    git = Git(args.repo_path)

    branches = git.get_branches()
    commits = git.get_commits()
    # TODO: Fix this for repo_path=(.|~)
    project_name = args.name if args.name is not None else os.path.basename(args.repo_path)
    tags = git.get_tags()

    gen = Generator(args.out_dir)
    gen.render_overview(project_name, branches, tags)
    gen.render_log(project_name, commits, branches, tags)

if __name__ == '__main__':
    main()