-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
93 lines (83 loc) · 1.67 KB
/
main.go
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* SPDX-FileCopyrightText: 2023 Mandelsoft.
*
* SPDX-License-Identifier: Apache-2.0
*/
package main
import (
"fmt"
"os"
"github.com/mandelsoft/mdgen/tree"
"github.com/mandelsoft/mdgen/version"
)
func Tree() {
print := false
copy := false
args := os.Args[1:]
if len(args) > 0 {
if args[0] == "--version" {
info := version.Get()
fmt.Printf("mdgen version %s.%s.%s (%s) [%s %s]\n", info.Major, info.Minor, info.Patch, info.PreRelease, info.GitTreeState, info.GitCommit)
os.Exit(0)
}
if args[0] == "--help" {
fmt.Printf("mdgen [--doc] [--copy] [<source dir> [<target dir>]]\n")
fmt.Printf(`
Flags:
--doc print doc graph
--copy copy used resources into target tree
mdgen generated GitHub consistently interlinked markdown files for a tree of mdg
source files (see https://github.com/mandelsoft/mdgen).
`)
os.Exit(0)
}
if args[0] == "--doc" {
print = true
args = args[1:]
}
if args[0] == "--copy" {
copy = true
args = args[1:]
}
}
if len(args) > 2 {
fmt.Printf("use mdgen [--doc] [<source> [<target>]]")
os.Exit(1)
}
src := "."
if len(args) > 0 {
src = args[0]
}
dst := "doc"
if len(args) > 1 {
dst = args[1]
}
t, err := tree.ForFolder(src)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}
t.SetCopyMode(copy)
if print {
t.Print("")
}
err = t.Resolve()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}
tw, err := tree.NewFileTreeWriter(dst)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}
tw.Close()
err = t.Emit(tw)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}
}
func main() {
Tree()
}