aboutsummaryrefslogtreecommitdiff
path: root/parser/parser.go
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-09-03 16:01:20 +0200
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-09-03 16:01:20 +0200
commita21602a450217333a27419d8168865b21fae6e7e (patch)
treebcb454130105de02dd97864dc1c977bf30044c38 /parser/parser.go
parent3b21449468a1b20b3ff706fe00a04556a804e627 (diff)
downloadapkdoc-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 'parser/parser.go')
-rw-r--r--parser/parser.go94
1 files changed, 0 insertions, 94 deletions
diff --git a/parser/parser.go b/parser/parser.go
deleted file mode 100644
index 62b0d85..0000000
--- a/parser/parser.go
+++ /dev/null
@@ -1,94 +0,0 @@
-package parser
-
-import (
- "fmt"
- "strconv"
- "strings"
- "time"
-)
-
-type (
- // https://wiki.alpinelinux.org/wiki/Apk_spec
- Entry struct {
- Checksum string // C
- Version string // V
- Name string // P
- Architecture *string // A
- PackageSize int // S
- InstalledSize int // I
- Description string // T
- Url string // U
- License string // L
- Origin *string // o
- Maintainer *string // m
- BuildTime *time.Time // t
- Commit *string // c
- ProviderPriority *int // k
- Dependencies []string // D
- Provides []string // p
- InstallIf []string // i
- }
-)
-
-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
-}
-
-func split(line string) (string, string) {
- parts := strings.SplitN(line, ":", 2)
- return parts[0], parts[1]
-}
-
-func toInt(v string) int {
- i, _ := strconv.Atoi(v)
- return i
-}
-
-func Parse(lines []string) *Entry {
- entry := &Entry{}
- for _, line := range lines {
- r, c := split(line)
- switch r {
- case "C":
- entry.Checksum = c
- case "V":
- entry.Version = c
- case "P":
- entry.Name = c
- case "A":
- entry.Architecture = &c
- case "S":
- entry.PackageSize = toInt(c)
- case "I":
- entry.InstalledSize = toInt(c)
- case "T":
- entry.Description = c
- case "U":
- entry.Url = c
- case "L":
- entry.License = c
- case "o":
- entry.Origin = &c
- case "m":
- entry.Maintainer = &c
- case "t":
- entry.BuildTime = ptr(time.Unix(int64(toInt(c)), 0))
- case "c":
- entry.Commit = &c
- case "k":
- entry.ProviderPriority = ptr(toInt(c))
- case "D":
- entry.Dependencies = strings.Split(c, " ")
- case "p":
- entry.Dependencies = strings.Split(c, " ")
- case "i":
- entry.Dependencies = strings.Split(c, " ")
- }
- }
- return entry
-}