ctucx.git: nimstagit

[nimlang] incomplete reimplementation of stagit

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 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 import os, times
import nimgit

import types, utils, assets

import index, repoGenerator

include "templates/index.nimf"

var config {.threadvar.}: Config

proc main =
    if paramCount() == 0:
        echo "No options given!"
        quit(QuitFailure)

    if paramCount() == 1:
        echo "No config given!"
        quit(QuitFailure)

    discard git_libgit2_init()

    config = readConfig(paramStr(2))

    if not dirExists(config.outputDirectory):
        echo "Output-directory does not exist!"
        quit(QuitFailure)

    case paramStr(1):
        of "index":
            let templateContext = TemplateContext(
                    siteTitle:   config.title,
                    description: config.description,
                    generated:   $now()
                )

            echo "Generate page: index.html"
            writeFile(
                joinPath(config.outputDirectory, "index.html"),
                templateIndexPage(templateContext, reposOverview(config))
            )
            echo "Create asset: style.css"
            writeFile(joinPath(config.outputDirectory, "style.css"), assetStyleCss)

        of "repo":
            if paramCount() > 2:
                if not config.projectsList.contains(paramStr(3)):
                    echo "The repo '" & paramStr(3) & "' is not in the projectsList/scanDir!"
                    quit(QuitFailure)

                repoGenerator(config, paramStr(3))

            else:
                for repo in config.projectsList:
                    repoGenerator(config, repo)

        else:
            echo "Unknown option: " & paramStr(1)
            echo "Valid options are: index,"

main()