-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (42 loc) · 1.08 KB
/
main.go
File metadata and controls
50 lines (42 loc) · 1.08 KB
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
package main
import (
"errors"
"fmt"
"io/ioutil"
"os"
"github.com/quortex/kapitan-docs/pkg/document"
"github.com/quortex/kapitan-docs/pkg/flags"
"github.com/quortex/kapitan-docs/pkg/kapitan"
log "github.com/sirupsen/logrus"
)
var opts flags.Options
func main() {
// Flags parsing
if err := flags.Parse(&opts); err != nil {
log.Error(fmt.Errorf("Invalid flags: %w", err))
os.Exit(1)
}
log.SetLevel(opts.LogLevel.Level)
// Project directory parsing
log.Debugf("Parsing project directory: %s", opts.Positional.Directory)
p, err := kapitan.NewProject(opts.Positional.Directory)
if err != nil {
log.Error(fmt.Errorf("Cannot parse project: %w", err))
os.Exit(1)
}
// Read given template file
f, err := ioutil.ReadFile(opts.TemplateFile)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
log.Error(fmt.Errorf("Read file error: %w", err))
os.Exit(1)
}
}
// Render markdown documentation
rendered, err := document.RenderAsMarkdown(p, string(f))
if err != nil {
log.Error(fmt.Errorf("Cannot render documentation: %w", err))
os.Exit(1)
}
fmt.Println(rendered)
}