apkdoc @ 3b21449468a1b20b3ff706fe00a04556a804e627

ref: Remove quicktemplate

This is done in preparation to use text-html/template. This will allow
the user to input their own template file
  1diff --git a/Makefile b/Makefile
  2index 820d664c3a9d5875b396eff4cfd668ccd0834690..00fc463cdcb8ff5c314f870a8c8ff76eb690f842 100644
  3--- a/Makefile
  4+++ b/Makefile
  5@@ -10,14 +10,10 @@
  6 run: tmpl
  7 	$(GO_RUN) .
  8 
  9-build: tmpl
 10+build:
 11 	$(GO_BUILD) \
 12 		-o $(OUT) \
 13 		.
 14 
 15 install: build
 16 	install -Dm755 $(OUT) $(BINDIR)/$(BIN)
 17-
 18-tmpl:
 19-	cd ./templates && \
 20-	qtc *
 21diff --git a/go.mod b/go.mod
 22index 66cf37dda6e09cd47f00ed6c86588d6e87ceb796..0529d054a67a3da2a4bc84c27613296196d27ad6 100644
 23--- a/go.mod
 24+++ b/go.mod
 25@@ -2,9 +2,4 @@ module git.sr.ht/~gabrielgio/apkdoc
 26 
 27 go 1.20
 28 
 29-require (
 30-	github.com/spf13/pflag v1.0.5
 31-	github.com/valyala/quicktemplate v1.7.0
 32-)
 33-
 34-require github.com/valyala/bytebufferpool v1.0.0 // indirect
 35+require github.com/spf13/pflag v1.0.5
 36diff --git a/go.sum b/go.sum
 37index ec4e9cf9cfdc351ce19f5c58eb68ec5ca39b1ee0..287f6fa8e2417922229405abc2669fe7b8fd93e0 100644
 38--- a/go.sum
 39+++ b/go.sum
 40@@ -1,23 +1,2 @@
 41-github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
 42-github.com/andybalholm/brotli v1.0.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
 43-github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
 44-github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
 45-github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
 46 github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
 47 github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
 48-github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
 49-github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
 50-github.com/valyala/fasthttp v1.30.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD3K/7o2Cus=
 51-github.com/valyala/quicktemplate v1.7.0 h1:LUPTJmlVcb46OOUY3IeD9DojFpAVbsG+5WFTcjMJzCM=
 52-github.com/valyala/quicktemplate v1.7.0/go.mod h1:sqKJnoaOF88V07vkO+9FL8fb9uZg/VPSJnLYn+LmLk8=
 53-github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
 54-golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
 55-golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
 56-golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 57-golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 58-golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 59-golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 60-golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 61-golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 62-golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 63-golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 64diff --git a/main.go b/main.go
 65index abeb557fe951b047a8b35b7b6c40533af7724667..fe3c34ff9c8a0fac6d77e6b41d7ebb7897ae4bbf 100644
 66--- a/main.go
 67+++ b/main.go
 68@@ -5,27 +5,14 @@ 	"archive/tar"
 69 	"bufio"
 70 	"compress/gzip"
 71 	"errors"
 72+	"fmt"
 73 	"io"
 74 	"net/http"
 75 	"os"
 76 
 77 	"git.sr.ht/~gabrielgio/apkdoc/parser"
 78-	"git.sr.ht/~gabrielgio/apkdoc/templates"
 79 	flag "github.com/spf13/pflag"
 80 )
 81-
 82-func fechIndex(url string) (io.ReadCloser, error) {
 83-	resp, err := http.Get(url)
 84-	if err != nil {
 85-		return nil, err
 86-	}
 87-
 88-	if resp.StatusCode != 200 {
 89-		return nil, errors.New("Invlid response")
 90-	}
 91-
 92-	return resp.Body, nil
 93-}
 94 
 95 func main() {
 96 	url := flag.StringP("url", "u", "", "Url to the APKINDEX.tar.gz")
 97@@ -74,10 +61,37 @@ 			lines = append(lines, l)
 98 		}
 99 	}
100 
101-	file, err := os.Create(*output)
102+	outputFile, err := getOutputFile(*output)
103+	if err != nil {
104+		panic("Error openning output file: " + err.Error())
105+	}
106+
107+	for _, e := range entries {
108+		fmt.Fprintln(outputFile, e.FomartLink(*repositoryFormat))
109+	}
110+}
111+
112+func getOutputFile(output string) (*os.File, error) {
113+	if output == "" {
114+		outputFile, err := os.Create(output)
115+		if err != nil {
116+			return nil, err
117+		}
118+		return outputFile, nil
119+	} else {
120+		return os.Stdout, nil
121+	}
122+}
123+
124+func fechIndex(url string) (io.ReadCloser, error) {
125+	resp, err := http.Get(url)
126 	if err != nil {
127-		panic("Error opening output file: " + err.Error())
128+		return nil, err
129 	}
130 
131-	templates.WriteMarkdownTemplate(file, entries, *repositoryFormat)
132+	if resp.StatusCode != 200 {
133+		return nil, errors.New("Invlid response")
134+	}
135+
136+	return resp.Body, nil
137 }
138diff --git a/parser/parser.go b/parser/parser.go
139index 8996b8cd81c06890f565e445197e6a8fbc4db895..62b0d855ba36b390d7eb5c6bcbe76294cad99bc5 100644
140--- a/parser/parser.go
141+++ b/parser/parser.go
142@@ -1,6 +1,7 @@
143 package parser
144 
145 import (
146+	"fmt"
147 	"strconv"
148 	"strings"
149 	"time"
150@@ -28,6 +29,11 @@ 		Provides         []string   // p
151 		InstallIf        []string   // i
152 	}
153 )
154+
155+func (e *Entry) FomartLink(format string) string {
156+	c := strings.Replace(*e.Commit, "-dirty", "", -1)
157+	return fmt.Sprintf(format, c, *e.Origin)
158+}
159 
160 func ptr[T any](v T) *T {
161 	return &v
162diff --git a/templates/index.md.qtpl b/templates/index.md.qtpl
163deleted file mode 100644
164index 434d64090a55531cb34b070cdc1cf88ee15d3d63..0000000000000000000000000000000000000000
165--- a/templates/index.md.qtpl
166+++ /dev/null
167@@ -1,39 +0,0 @@
168-{% import "fmt" %}
169-{% import "strings" %}
170-{% import "git.sr.ht/~gabrielgio/apkdoc/parser" %}
171-
172-{% code 
173-func reduce(lines []string) string {
174-    return strings.Join(lines, " ")
175-}
176-
177-func formatLink(e *parser.Entry, format string) string {
178-    c := strings.Replace(*e.Commit, "-dirty", "", -1)
179-    return fmt.Sprintf(format, c, *e.Origin)
180-}
181-%}
182-
183-{% func MarkdownTemplate(entries []*parser.Entry, format string) %}
184-# Apks Alpine 3.18
185-{% for _, e := range entries %}
186-## {%s e.Name %}
187-
188-- **Version**: {%s e.Version%}
189-- **Description**: {%s e.Description%}{% if e.Maintainer != nil %}
190-- **Maintainer**: {%s *e.Maintainer%}{% endif %}
191-- **Checksum**:{%s e.Checksum%}{% if e.Architecture != nil %}
192-- **Architecture**: {%s *e.Architecture%}{% endif %}
193-- **Size**: {%d e.PackageSize%}B
194-- **Installed size**: {%d e.InstalledSize%}
195-- **Url**: {%s e.Url%}
196-- **License**: {%s e.License%}{% if e.Origin != nil %}
197-- **Origin**: {%s *e.Origin%}{% endif %}{% if e.BuildTime != nil %}
198-- **Build time**: {%s e.BuildTime.String() %}{% endif %}{% if e.Commit != nil %}
199-- **Commit**: [{%s *e.Commit %}]({%s formatLink(e, format) %}){% endif %}{% if e.ProviderPriority != nil %}
200-- **Provider Priority**: {%d *e.ProviderPriority %}{% endif %}{% if len(e.Dependencies) > 0 %}
201-- **Dependencies:**: {%s reduce(e.Dependencies) %}{% endif %}{% if len(e.Provides) > 0 %}
202-- **Provides:**: {%s reduce(e.Provides) %}{% endif %}{% if len(e.InstallIf) > 0 %}
203-- **Install if:**: {%s reduce(e.InstallIf) %}{% endif %}
204-{% endfor %}
205-
206-{% endfunc %}
207diff --git a/templates/index.md.qtpl.go b/templates/index.md.qtpl.go
208deleted file mode 100644
209index c87d94794faa3dcbd9a9b07647af67a631cc8b34..0000000000000000000000000000000000000000
210--- a/templates/index.md.qtpl.go
211+++ /dev/null
212@@ -1,211 +0,0 @@
213-// Code generated by qtc from "index.md.qtpl". DO NOT EDIT.
214-// See https://github.com/valyala/quicktemplate for details.
215-
216-//line index.md.qtpl:1
217-package templates
218-
219-//line index.md.qtpl:1
220-import "fmt"
221-
222-//line index.md.qtpl:2
223-import "strings"
224-
225-//line index.md.qtpl:3
226-import "git.sr.ht/~gabrielgio/apkdoc/parser"
227-
228-//line index.md.qtpl:5
229-import (
230-	qtio422016 "io"
231-
232-	qt422016 "github.com/valyala/quicktemplate"
233-)
234-
235-//line index.md.qtpl:5
236-var (
237-	_ = qtio422016.Copy
238-	_ = qt422016.AcquireByteBuffer
239-)
240-
241-//line index.md.qtpl:6
242-func reduce(lines []string) string {
243-	return strings.Join(lines, " ")
244-}
245-
246-func formatLink(e *parser.Entry, format string) string {
247-	c := strings.Replace(*e.Commit, "-dirty", "", -1)
248-	return fmt.Sprintf(format, c, *e.Origin)
249-}
250-
251-//line index.md.qtpl:16
252-func StreamMarkdownTemplate(qw422016 *qt422016.Writer, entries []*parser.Entry, format string) {
253-//line index.md.qtpl:16
254-	qw422016.N().S(`
255-# Apks Alpine 3.18
256-`)
257-//line index.md.qtpl:18
258-	for _, e := range entries {
259-//line index.md.qtpl:18
260-		qw422016.N().S(`
261-## `)
262-//line index.md.qtpl:19
263-		qw422016.E().S(e.Name)
264-//line index.md.qtpl:19
265-		qw422016.N().S(`
266-
267-- **Version**: `)
268-//line index.md.qtpl:21
269-		qw422016.E().S(e.Version)
270-//line index.md.qtpl:21
271-		qw422016.N().S(`
272-- **Description**: `)
273-//line index.md.qtpl:22
274-		qw422016.E().S(e.Description)
275-//line index.md.qtpl:22
276-		if e.Maintainer != nil {
277-//line index.md.qtpl:22
278-			qw422016.N().S(`
279-- **Maintainer**: `)
280-//line index.md.qtpl:23
281-			qw422016.E().S(*e.Maintainer)
282-//line index.md.qtpl:23
283-		}
284-//line index.md.qtpl:23
285-		qw422016.N().S(`
286-- **Checksum**:`)
287-//line index.md.qtpl:24
288-		qw422016.E().S(e.Checksum)
289-//line index.md.qtpl:24
290-		if e.Architecture != nil {
291-//line index.md.qtpl:24
292-			qw422016.N().S(`
293-- **Architecture**: `)
294-//line index.md.qtpl:25
295-			qw422016.E().S(*e.Architecture)
296-//line index.md.qtpl:25
297-		}
298-//line index.md.qtpl:25
299-		qw422016.N().S(`
300-- **Size**: `)
301-//line index.md.qtpl:26
302-		qw422016.N().D(e.PackageSize)
303-//line index.md.qtpl:26
304-		qw422016.N().S(`B
305-- **Installed size**: `)
306-//line index.md.qtpl:27
307-		qw422016.N().D(e.InstalledSize)
308-//line index.md.qtpl:27
309-		qw422016.N().S(`
310-- **Url**: `)
311-//line index.md.qtpl:28
312-		qw422016.E().S(e.Url)
313-//line index.md.qtpl:28
314-		qw422016.N().S(`
315-- **License**: `)
316-//line index.md.qtpl:29
317-		qw422016.E().S(e.License)
318-//line index.md.qtpl:29
319-		if e.Origin != nil {
320-//line index.md.qtpl:29
321-			qw422016.N().S(`
322-- **Origin**: `)
323-//line index.md.qtpl:30
324-			qw422016.E().S(*e.Origin)
325-//line index.md.qtpl:30
326-		}
327-//line index.md.qtpl:30
328-		if e.BuildTime != nil {
329-//line index.md.qtpl:30
330-			qw422016.N().S(`
331-- **Build time**: `)
332-//line index.md.qtpl:31
333-			qw422016.E().S(e.BuildTime.String())
334-//line index.md.qtpl:31
335-		}
336-//line index.md.qtpl:31
337-		if e.Commit != nil {
338-//line index.md.qtpl:31
339-			qw422016.N().S(`
340-- **Commit**: [`)
341-//line index.md.qtpl:32
342-			qw422016.E().S(*e.Commit)
343-//line index.md.qtpl:32
344-			qw422016.N().S(`](`)
345-//line index.md.qtpl:32
346-			qw422016.E().S(formatLink(e, format))
347-//line index.md.qtpl:32
348-			qw422016.N().S(`)`)
349-//line index.md.qtpl:32
350-		}
351-//line index.md.qtpl:32
352-		if e.ProviderPriority != nil {
353-//line index.md.qtpl:32
354-			qw422016.N().S(`
355-- **Provider Priority**: `)
356-//line index.md.qtpl:33
357-			qw422016.N().D(*e.ProviderPriority)
358-//line index.md.qtpl:33
359-		}
360-//line index.md.qtpl:33
361-		if len(e.Dependencies) > 0 {
362-//line index.md.qtpl:33
363-			qw422016.N().S(`
364-- **Dependencies:**: `)
365-//line index.md.qtpl:34
366-			qw422016.E().S(reduce(e.Dependencies))
367-//line index.md.qtpl:34
368-		}
369-//line index.md.qtpl:34
370-		if len(e.Provides) > 0 {
371-//line index.md.qtpl:34
372-			qw422016.N().S(`
373-- **Provides:**: `)
374-//line index.md.qtpl:35
375-			qw422016.E().S(reduce(e.Provides))
376-//line index.md.qtpl:35
377-		}
378-//line index.md.qtpl:35
379-		if len(e.InstallIf) > 0 {
380-//line index.md.qtpl:35
381-			qw422016.N().S(`
382-- **Install if:**: `)
383-//line index.md.qtpl:36
384-			qw422016.E().S(reduce(e.InstallIf))
385-//line index.md.qtpl:36
386-		}
387-//line index.md.qtpl:36
388-		qw422016.N().S(`
389-`)
390-//line index.md.qtpl:37
391-	}
392-//line index.md.qtpl:37
393-	qw422016.N().S(`
394-
395-`)
396-//line index.md.qtpl:39
397-}
398-
399-//line index.md.qtpl:39
400-func WriteMarkdownTemplate(qq422016 qtio422016.Writer, entries []*parser.Entry, format string) {
401-//line index.md.qtpl:39
402-	qw422016 := qt422016.AcquireWriter(qq422016)
403-//line index.md.qtpl:39
404-	StreamMarkdownTemplate(qw422016, entries, format)
405-//line index.md.qtpl:39
406-	qt422016.ReleaseWriter(qw422016)
407-//line index.md.qtpl:39
408-}
409-
410-//line index.md.qtpl:39
411-func MarkdownTemplate(entries []*parser.Entry, format string) string {
412-//line index.md.qtpl:39
413-	qb422016 := qt422016.AcquireByteBuffer()
414-//line index.md.qtpl:39
415-	WriteMarkdownTemplate(qb422016, entries, format)
416-//line index.md.qtpl:39
417-	qs422016 := string(qb422016.B)
418-//line index.md.qtpl:39
419-	qt422016.ReleaseByteBuffer(qb422016)
420-//line index.md.qtpl:39
421-	return qs422016
422-//line index.md.qtpl:39
423-}