Skip to content

Commit

Permalink
fix group expansion for local file
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Jan 12, 2024
1 parent 9edea09 commit 06db9e0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
22 changes: 11 additions & 11 deletions batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import (
"golang.org/x/sync/errgroup"
)

type Group []string

type Batch struct {
Groups map[string][]string `json:"groups"`
Admins []string `json:"admins"`
Files map[string][]string `json:"files"`
OutDir string `json:"outDir"`
Groups map[string]Group `json:"groups"`
Admins Group `json:"admins"`
Files map[string]Group `json:"files"`
OutDir string `json:"outDir"`

root string
}
Expand Down Expand Up @@ -108,18 +110,16 @@ func (b *Batch) ExpandFiles() (map[string][]string, error) { //nolint: gocognit
expanded := []string{}
members = append(members, b.Admins...)
for _, member := range members {
if !strings.HasPrefix(member, "@") {
member = filepath.Join(b.root, member)
}

if strings.HasPrefix(member, "$") {
switch {
case strings.HasPrefix(member, "$"):
if _, ok := groups[member]; !ok {
return nil, fmt.Errorf("%w: %s", ErrGroupNotDefined, member)
}

expanded = append(expanded, groups[member]...)
} else {
case strings.HasPrefix(member, "@"):
expanded = append(expanded, member)
default:
expanded = append(expanded, filepath.Join(b.root, member))
}
}

Expand Down
8 changes: 4 additions & 4 deletions batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestBatchGroups(t *testing.T) {
g := got.T(t)

batch := Batch{
Groups: map[string][]string{
Groups: map[string]Group{
"$a": {"a", "b"},
"$b": {"c", "$a"},
"$c": {"$b"},
Expand All @@ -24,7 +24,7 @@ func TestBatchGroups(t *testing.T) {

{
batch := Batch{
Groups: map[string][]string{
Groups: map[string]Group{
"$a": {"$b"},
"$b": {"$a"},
},
Expand All @@ -43,10 +43,10 @@ func TestBatchFiles(t *testing.T) {
g.WriteFile(filepath.FromSlash(p), "hello world!")

batch := Batch{
Files: map[string][]string{
Files: map[string]Group{
p: {"$c", "d"},
},
Groups: map[string][]string{
Groups: map[string]Group{
"$a": {"a", "b"},
"$b": {"c", "$a"},
"$c": {"$b"},
Expand Down
2 changes: 1 addition & 1 deletion lib/whisper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

const (
APIVersion = "v0.8.9"
APIVersion = "v0.8.10"
WireFormatVersion = byte(8)
)

Expand Down

0 comments on commit 06db9e0

Please sign in to comment.