diff --git a/cmd/fdroidcl/main.go b/cmd/fdroidcl/main.go index 172674b..cd67ebb 100644 --- a/cmd/fdroidcl/main.go +++ b/cmd/fdroidcl/main.go @@ -17,9 +17,6 @@ import ( const ( cmdName = "fdroidcl" - - repoName = "repo" - repoURL = "https://f-droid.org/repo" ) func subdir(dir, name string) string { @@ -47,16 +44,18 @@ func mustConfig() string { } type Repo struct { + ID string `json:"id"` URL string `json:"url"` } type userConfig struct { - Repos map[string]Repo `json:"repos"` + Repos []Repo `json:"repos"` } var config = userConfig{ - Repos: map[string]Repo{ - "f-droid": { + Repos: []Repo{ + { + ID: "f-droid", URL: "https://f-droid.org/repo", }, }, @@ -89,6 +88,13 @@ func readConfig() { } } +func mustOneRepo() *Repo { + if len(config.Repos) != 1 { + log.Fatalf("Exactly one repo is needed") + } + return &config.Repos[0] +} + // A Command is an implementation of a go command // like go build or go fix. type Command struct { diff --git a/cmd/fdroidcl/update.go b/cmd/fdroidcl/update.go index 3a56511..c2d7f87 100644 --- a/cmd/fdroidcl/update.go +++ b/cmd/fdroidcl/update.go @@ -34,8 +34,9 @@ func runUpdate(args []string) { } func updateIndex() error { - url := fmt.Sprintf("%s/%s", repoURL, "index.jar") - if err := downloadEtag(url, indexPath(repoName), nil); err != nil { + repo := mustOneRepo() + url := fmt.Sprintf("%s/%s", repo.URL, "index.jar") + if err := downloadEtag(url, indexPath(repo.ID), nil); err != nil { return err } return nil @@ -101,11 +102,12 @@ func downloadEtag(url, path string, sum []byte) error { } func indexPath(name string) string { - return filepath.Join(mustConfig(), repoName+".jar") + return filepath.Join(mustConfig(), name+".jar") } func mustLoadIndex() *fdroidcl.Index { - p := indexPath(repoName) + repo := mustOneRepo() + p := indexPath(repo.ID) f, err := os.Open(p) if err != nil { log.Fatalf("Could not open index file: %v", err)