Skip to content

Commit

Permalink
added markdown and html export options
Browse files Browse the repository at this point in the history
Signed-off-by: Rahul Jadhav <[email protected]>
  • Loading branch information
nyrahul committed Jun 30, 2023
1 parent 90814ef commit ac72d5b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
6 changes: 4 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import (
)

type TableConfig struct {
Title string `yaml:"title"`
Caption string `yaml:"caption"`
Title string `yaml:"title"`
Caption string `yaml:"caption"`
Markdown string `yaml:"markdown"`
Html string `yaml:"html"`
}

type Paint struct {
Expand Down
22 changes: 21 additions & 1 deletion pkg/drawtable/csv2table.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ func getAllColConfigs(hdr []string, cols []config.ColConfig) []table.ColumnConfi
return colcfgs
}

func write2file(t table.Writer, fname string, ftype string) {
if fname == "" {
return
}
f, err := os.Create(fname)
if err != nil {
log.Fatalf("could not create file %s", fname)
}
defer f.Close()
t.SetOutputMirror(f)
if ftype == "md" {
log.Println("rendering MD")
t.RenderMarkdown()
} else if ftype == "html" {
log.Println("rendering HTML")
t.RenderHTML()
}
}

func Csv2Table(cfg config.Config) {
records := readCsvFile(cfg.InFile)
if len(records) <= 1 {
Expand Down Expand Up @@ -190,5 +209,6 @@ func Csv2Table(cfg config.Config) {
})
t.SetStyle(table.StyleLight)
t.Render()
// t.RenderMarkdown()
write2file(t, cfg.YamlCfg.Table.Markdown, "md")
write2file(t, cfg.YamlCfg.Table.Html, "html")
}
2 changes: 2 additions & 0 deletions tests/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
---
table:
title: "Kubernetes Cluster Service Ports status"
markdown: /tmp/out.md
html: /tmp/out.html
columns:
- name: Name
maxwidth: 30
Expand Down

0 comments on commit ac72d5b

Please sign in to comment.