aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go48
1 files changed, 31 insertions, 17 deletions
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
}