diff options
author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-09-03 16:01:20 +0200 |
---|---|---|
committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-09-03 16:01:20 +0200 |
commit | a21602a450217333a27419d8168865b21fae6e7e (patch) | |
tree | bcb454130105de02dd97864dc1c977bf30044c38 /main.go | |
parent | 3b21449468a1b20b3ff706fe00a04556a804e627 (diff) | |
download | apkdoc-a21602a450217333a27419d8168865b21fae6e7e.tar.gz apkdoc-a21602a450217333a27419d8168865b21fae6e7e.tar.bz2 apkdoc-a21602a450217333a27419d8168865b21fae6e7e.zip |
feat: Add option for inputing template
Now a template file is required to run the cli command. That gives the
user an option to provide its own template file.
An default will be provided later.
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -5,19 +5,18 @@ import ( "bufio" "compress/gzip" "errors" - "fmt" "io" "net/http" "os" - "git.sr.ht/~gabrielgio/apkdoc/parser" flag "github.com/spf13/pflag" ) func main() { url := flag.StringP("url", "u", "", "Url to the APKINDEX.tar.gz") output := flag.StringP("output", "o", "index.md", "Output path") - repositoryFormat := flag.StringP("repository-format", "f", "https://git.sr.ht/~gabrielgio/apkbuilds/tree/%s/item/apks/%s", "Template to build repository link") + templateType := flag.StringP("template-type", "p", "text", "Template system to be used, options: html, text") + templateFile := flag.StringP("template-file", "t", "text", "Template file to be used") flag.Parse() tarStream, err := fechIndex(*url) @@ -47,13 +46,13 @@ func main() { s := bufio.NewScanner(tr) - entries := make([]*parser.Entry, 0) + entries := make([]*Entry, 0) lines := make([]string, 0) for s.Scan() { l := s.Text() if l == "" { - entry := parser.Parse(lines) + entry := Parse(lines) entries = append(entries, entry) lines = make([]string, 0) } else { @@ -66,13 +65,16 @@ func main() { panic("Error openning output file: " + err.Error()) } - for _, e := range entries { - fmt.Fprintln(outputFile, e.FomartLink(*repositoryFormat)) + tmpl, err := GetTemplate(*templateType, *templateFile) + if err != nil { + panic("Error loading template file: " + err.Error()) } + + tmpl.Execute(outputFile, entries) } func getOutputFile(output string) (*os.File, error) { - if output == "" { + if output != "" { outputFile, err := os.Create(output) if err != nil { return nil, err |