Skip to content

Commit

Permalink
chore: update json structure and format
Browse files Browse the repository at this point in the history
  • Loading branch information
telemachus committed Dec 16, 2024
1 parent 4b179de commit 97c4475
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
10 changes: 7 additions & 3 deletions internal/cli/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@ func (app *appEnv) repos() []Repo {
return nil
}

rs := make([]Repo, 0, 20)
err = json.Unmarshal(conf, &rs)
cfg := struct {
Repos []Repo `json:"repos"`
}{
Repos: make([]Repo, 0, 20),
}
err = json.Unmarshal(conf, &cfg)
if err != nil {
app.exitVal = exitFailure
fmt.Fprintf(os.Stderr, "%s %s: %s\n", app.cmd, app.subCmd, err)
return nil
}

// Every repository must have a URL and a directory name.
return slices.DeleteFunc(rs, func(r Repo) bool {
return slices.DeleteFunc(cfg.Repos, func(r Repo) bool {
return r.URL == "" || r.Name == ""
})
}
30 changes: 16 additions & 14 deletions internal/cli/testdata/backups.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
[
{
"url": "https://github.com/foo/foo.git",
"name": "foo.git"
},
{
"url": "https://github.com/bar/bar.git",
"name": "bar.git"
},
{
"url": "https://example.com/buzz/fizz.git",
"name": "random.git"
}
]
{
"repos": [
{
"name": "foo.git",
"url": "https://github.com/foo/foo.git"
},
{
"name": "bar.git",
"url": "https://github.com/bar/bar.git"
},
{
"name": "random.git",
"url": "https://example.com/buzz/fizz.git"
}
]
}
22 changes: 12 additions & 10 deletions internal/cli/testdata/repo-checks.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[
{
"url": "https://github.com/user/repo.git",
"name": ""
},
{
"url": "",
"name": "repo.git"
}
]
{
"repos": [
{
"name": "",
"url": "https://github.com/user/repo.git"
},
{
"name": "repo.git",
"url": ""
}
]
}

0 comments on commit 97c4475

Please sign in to comment.