aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--go.mod7
-rw-r--r--go.sum21
-rw-r--r--main.go48
-rw-r--r--parser/parser.go6
-rw-r--r--templates/index.md.qtpl39
-rw-r--r--templates/index.md.qtpl.go211
7 files changed, 39 insertions, 299 deletions
diff --git a/Makefile b/Makefile
index 820d664..00fc463 100644
--- a/Makefile
+++ b/Makefile
@@ -10,14 +10,10 @@ all: build
run: tmpl
$(GO_RUN) .
-build: tmpl
+build:
$(GO_BUILD) \
-o $(OUT) \
.
install: build
install -Dm755 $(OUT) $(BINDIR)/$(BIN)
-
-tmpl:
- cd ./templates && \
- qtc *
diff --git a/go.mod b/go.mod
index 66cf37d..0529d05 100644
--- a/go.mod
+++ b/go.mod
@@ -2,9 +2,4 @@ module git.sr.ht/~gabrielgio/apkdoc
go 1.20
-require (
- github.com/spf13/pflag v1.0.5
- github.com/valyala/quicktemplate v1.7.0
-)
-
-require github.com/valyala/bytebufferpool v1.0.0 // indirect
+require github.com/spf13/pflag v1.0.5
diff --git a/go.sum b/go.sum
index ec4e9cf..287f6fa 100644
--- a/go.sum
+++ b/go.sum
@@ -1,23 +1,2 @@
-github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
-github.com/andybalholm/brotli v1.0.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
-github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
-github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
-github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
-github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
-github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
-github.com/valyala/fasthttp v1.30.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD3K/7o2Cus=
-github.com/valyala/quicktemplate v1.7.0 h1:LUPTJmlVcb46OOUY3IeD9DojFpAVbsG+5WFTcjMJzCM=
-github.com/valyala/quicktemplate v1.7.0/go.mod h1:sqKJnoaOF88V07vkO+9FL8fb9uZg/VPSJnLYn+LmLk8=
-github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
-golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
-golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
-golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
-golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
-golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
diff --git a/main.go b/main.go
index abeb557..fe3c34f 100644
--- a/main.go
+++ b/main.go
@@ -5,28 +5,15 @@ import (
"bufio"
"compress/gzip"
"errors"
+ "fmt"
"io"
"net/http"
"os"
"git.sr.ht/~gabrielgio/apkdoc/parser"
- "git.sr.ht/~gabrielgio/apkdoc/templates"
flag "github.com/spf13/pflag"
)
-func fechIndex(url string) (io.ReadCloser, error) {
- resp, err := http.Get(url)
- if err != nil {
- return nil, err
- }
-
- if resp.StatusCode != 200 {
- return nil, errors.New("Invlid response")
- }
-
- return resp.Body, nil
-}
-
func main() {
url := flag.StringP("url", "u", "", "Url to the APKINDEX.tar.gz")
output := flag.StringP("output", "o", "index.md", "Output path")
@@ -74,10 +61,37 @@ func main() {
}
}
- file, err := os.Create(*output)
+ outputFile, err := getOutputFile(*output)
+ if err != nil {
+ panic("Error openning output file: " + err.Error())
+ }
+
+ for _, e := range entries {
+ fmt.Fprintln(outputFile, e.FomartLink(*repositoryFormat))
+ }
+}
+
+func getOutputFile(output string) (*os.File, error) {
+ if output == "" {
+ outputFile, err := os.Create(output)
+ if err != nil {
+ return nil, err
+ }
+ return outputFile, nil
+ } else {
+ return os.Stdout, nil
+ }
+}
+
+func fechIndex(url string) (io.ReadCloser, error) {
+ resp, err := http.Get(url)
if err != nil {
- panic("Error opening output file: " + err.Error())
+ return nil, err
+ }
+
+ if resp.StatusCode != 200 {
+ return nil, errors.New("Invlid response")
}
- templates.WriteMarkdownTemplate(file, entries, *repositoryFormat)
+ return resp.Body, nil
}
diff --git a/parser/parser.go b/parser/parser.go
index 8996b8c..62b0d85 100644
--- a/parser/parser.go
+++ b/parser/parser.go
@@ -1,6 +1,7 @@
package parser
import (
+ "fmt"
"strconv"
"strings"
"time"
@@ -29,6 +30,11 @@ type (
}
)
+func (e *Entry) FomartLink(format string) string {
+ c := strings.Replace(*e.Commit, "-dirty", "", -1)
+ return fmt.Sprintf(format, c, *e.Origin)
+}
+
func ptr[T any](v T) *T {
return &v
}
diff --git a/templates/index.md.qtpl b/templates/index.md.qtpl
deleted file mode 100644
index 434d640..0000000
--- a/templates/index.md.qtpl
+++ /dev/null
@@ -1,39 +0,0 @@
-{% import "fmt" %}
-{% import "strings" %}
-{% import "git.sr.ht/~gabrielgio/apkdoc/parser" %}
-
-{% code
-func reduce(lines []string) string {
- return strings.Join(lines, " ")
-}
-
-func formatLink(e *parser.Entry, format string) string {
- c := strings.Replace(*e.Commit, "-dirty", "", -1)
- return fmt.Sprintf(format, c, *e.Origin)
-}
-%}
-
-{% func MarkdownTemplate(entries []*parser.Entry, format string) %}
-# Apks Alpine 3.18
-{% for _, e := range entries %}
-## {%s e.Name %}
-
-- **Version**: {%s e.Version%}
-- **Description**: {%s e.Description%}{% if e.Maintainer != nil %}
-- **Maintainer**: {%s *e.Maintainer%}{% endif %}
-- **Checksum**:{%s e.Checksum%}{% if e.Architecture != nil %}
-- **Architecture**: {%s *e.Architecture%}{% endif %}
-- **Size**: {%d e.PackageSize%}B
-- **Installed size**: {%d e.InstalledSize%}
-- **Url**: {%s e.Url%}
-- **License**: {%s e.License%}{% if e.Origin != nil %}
-- **Origin**: {%s *e.Origin%}{% endif %}{% if e.BuildTime != nil %}
-- **Build time**: {%s e.BuildTime.String() %}{% endif %}{% if e.Commit != nil %}
-- **Commit**: [{%s *e.Commit %}]({%s formatLink(e, format) %}){% endif %}{% if e.ProviderPriority != nil %}
-- **Provider Priority**: {%d *e.ProviderPriority %}{% endif %}{% if len(e.Dependencies) > 0 %}
-- **Dependencies:**: {%s reduce(e.Dependencies) %}{% endif %}{% if len(e.Provides) > 0 %}
-- **Provides:**: {%s reduce(e.Provides) %}{% endif %}{% if len(e.InstallIf) > 0 %}
-- **Install if:**: {%s reduce(e.InstallIf) %}{% endif %}
-{% endfor %}
-
-{% endfunc %}
diff --git a/templates/index.md.qtpl.go b/templates/index.md.qtpl.go
deleted file mode 100644
index c87d947..0000000
--- a/templates/index.md.qtpl.go
+++ /dev/null
@@ -1,211 +0,0 @@
-// Code generated by qtc from "index.md.qtpl". DO NOT EDIT.
-// See https://github.com/valyala/quicktemplate for details.
-
-//line index.md.qtpl:1
-package templates
-
-//line index.md.qtpl:1
-import "fmt"
-
-//line index.md.qtpl:2
-import "strings"
-
-//line index.md.qtpl:3
-import "git.sr.ht/~gabrielgio/apkdoc/parser"
-
-//line index.md.qtpl:5
-import (
- qtio422016 "io"
-
- qt422016 "github.com/valyala/quicktemplate"
-)
-
-//line index.md.qtpl:5
-var (
- _ = qtio422016.Copy
- _ = qt422016.AcquireByteBuffer
-)
-
-//line index.md.qtpl:6
-func reduce(lines []string) string {
- return strings.Join(lines, " ")
-}
-
-func formatLink(e *parser.Entry, format string) string {
- c := strings.Replace(*e.Commit, "-dirty", "", -1)
- return fmt.Sprintf(format, c, *e.Origin)
-}
-
-//line index.md.qtpl:16
-func StreamMarkdownTemplate(qw422016 *qt422016.Writer, entries []*parser.Entry, format string) {
-//line index.md.qtpl:16
- qw422016.N().S(`
-# Apks Alpine 3.18
-`)
-//line index.md.qtpl:18
- for _, e := range entries {
-//line index.md.qtpl:18
- qw422016.N().S(`
-## `)
-//line index.md.qtpl:19
- qw422016.E().S(e.Name)
-//line index.md.qtpl:19
- qw422016.N().S(`
-
-- **Version**: `)
-//line index.md.qtpl:21
- qw422016.E().S(e.Version)
-//line index.md.qtpl:21
- qw422016.N().S(`
-- **Description**: `)
-//line index.md.qtpl:22
- qw422016.E().S(e.Description)
-//line index.md.qtpl:22
- if e.Maintainer != nil {
-//line index.md.qtpl:22
- qw422016.N().S(`
-- **Maintainer**: `)
-//line index.md.qtpl:23
- qw422016.E().S(*e.Maintainer)
-//line index.md.qtpl:23
- }
-//line index.md.qtpl:23
- qw422016.N().S(`
-- **Checksum**:`)
-//line index.md.qtpl:24
- qw422016.E().S(e.Checksum)
-//line index.md.qtpl:24
- if e.Architecture != nil {
-//line index.md.qtpl:24
- qw422016.N().S(`
-- **Architecture**: `)
-//line index.md.qtpl:25
- qw422016.E().S(*e.Architecture)
-//line index.md.qtpl:25
- }
-//line index.md.qtpl:25
- qw422016.N().S(`
-- **Size**: `)
-//line index.md.qtpl:26
- qw422016.N().D(e.PackageSize)
-//line index.md.qtpl:26
- qw422016.N().S(`B
-- **Installed size**: `)
-//line index.md.qtpl:27
- qw422016.N().D(e.InstalledSize)
-//line index.md.qtpl:27
- qw422016.N().S(`
-- **Url**: `)
-//line index.md.qtpl:28
- qw422016.E().S(e.Url)
-//line index.md.qtpl:28
- qw422016.N().S(`
-- **License**: `)
-//line index.md.qtpl:29
- qw422016.E().S(e.License)
-//line index.md.qtpl:29
- if e.Origin != nil {
-//line index.md.qtpl:29
- qw422016.N().S(`
-- **Origin**: `)
-//line index.md.qtpl:30
- qw422016.E().S(*e.Origin)
-//line index.md.qtpl:30
- }
-//line index.md.qtpl:30
- if e.BuildTime != nil {
-//line index.md.qtpl:30
- qw422016.N().S(`
-- **Build time**: `)
-//line index.md.qtpl:31
- qw422016.E().S(e.BuildTime.String())
-//line index.md.qtpl:31
- }
-//line index.md.qtpl:31
- if e.Commit != nil {
-//line index.md.qtpl:31
- qw422016.N().S(`
-- **Commit**: [`)
-//line index.md.qtpl:32
- qw422016.E().S(*e.Commit)
-//line index.md.qtpl:32
- qw422016.N().S(`](`)
-//line index.md.qtpl:32
- qw422016.E().S(formatLink(e, format))
-//line index.md.qtpl:32
- qw422016.N().S(`)`)
-//line index.md.qtpl:32
- }
-//line index.md.qtpl:32
- if e.ProviderPriority != nil {
-//line index.md.qtpl:32
- qw422016.N().S(`
-- **Provider Priority**: `)
-//line index.md.qtpl:33
- qw422016.N().D(*e.ProviderPriority)
-//line index.md.qtpl:33
- }
-//line index.md.qtpl:33
- if len(e.Dependencies) > 0 {
-//line index.md.qtpl:33
- qw422016.N().S(`
-- **Dependencies:**: `)
-//line index.md.qtpl:34
- qw422016.E().S(reduce(e.Dependencies))
-//line index.md.qtpl:34
- }
-//line index.md.qtpl:34
- if len(e.Provides) > 0 {
-//line index.md.qtpl:34
- qw422016.N().S(`
-- **Provides:**: `)
-//line index.md.qtpl:35
- qw422016.E().S(reduce(e.Provides))
-//line index.md.qtpl:35
- }
-//line index.md.qtpl:35
- if len(e.InstallIf) > 0 {
-//line index.md.qtpl:35
- qw422016.N().S(`
-- **Install if:**: `)
-//line index.md.qtpl:36
- qw422016.E().S(reduce(e.InstallIf))
-//line index.md.qtpl:36
- }
-//line index.md.qtpl:36
- qw422016.N().S(`
-`)
-//line index.md.qtpl:37
- }
-//line index.md.qtpl:37
- qw422016.N().S(`
-
-`)
-//line index.md.qtpl:39
-}
-
-//line index.md.qtpl:39
-func WriteMarkdownTemplate(qq422016 qtio422016.Writer, entries []*parser.Entry, format string) {
-//line index.md.qtpl:39
- qw422016 := qt422016.AcquireWriter(qq422016)
-//line index.md.qtpl:39
- StreamMarkdownTemplate(qw422016, entries, format)
-//line index.md.qtpl:39
- qt422016.ReleaseWriter(qw422016)
-//line index.md.qtpl:39
-}
-
-//line index.md.qtpl:39
-func MarkdownTemplate(entries []*parser.Entry, format string) string {
-//line index.md.qtpl:39
- qb422016 := qt422016.AcquireByteBuffer()
-//line index.md.qtpl:39
- WriteMarkdownTemplate(qb422016, entries, format)
-//line index.md.qtpl:39
- qs422016 := string(qb422016.B)
-//line index.md.qtpl:39
- qt422016.ReleaseByteBuffer(qb422016)
-//line index.md.qtpl:39
- return qs422016
-//line index.md.qtpl:39
-}