Skip to content

Commit 06db9e0

Browse files
committed
fix group expansion for local file
1 parent 9edea09 commit 06db9e0

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

batch.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ import (
1616
"golang.org/x/sync/errgroup"
1717
)
1818

19+
type Group []string
20+
1921
type Batch struct {
20-
Groups map[string][]string `json:"groups"`
21-
Admins []string `json:"admins"`
22-
Files map[string][]string `json:"files"`
23-
OutDir string `json:"outDir"`
22+
Groups map[string]Group `json:"groups"`
23+
Admins Group `json:"admins"`
24+
Files map[string]Group `json:"files"`
25+
OutDir string `json:"outDir"`
2426

2527
root string
2628
}
@@ -108,18 +110,16 @@ func (b *Batch) ExpandFiles() (map[string][]string, error) { //nolint: gocognit
108110
expanded := []string{}
109111
members = append(members, b.Admins...)
110112
for _, member := range members {
111-
if !strings.HasPrefix(member, "@") {
112-
member = filepath.Join(b.root, member)
113-
}
114-
115-
if strings.HasPrefix(member, "$") {
113+
switch {
114+
case strings.HasPrefix(member, "$"):
116115
if _, ok := groups[member]; !ok {
117116
return nil, fmt.Errorf("%w: %s", ErrGroupNotDefined, member)
118117
}
119-
120118
expanded = append(expanded, groups[member]...)
121-
} else {
119+
case strings.HasPrefix(member, "@"):
122120
expanded = append(expanded, member)
121+
default:
122+
expanded = append(expanded, filepath.Join(b.root, member))
123123
}
124124
}
125125

batch_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func TestBatchGroups(t *testing.T) {
1111
g := got.T(t)
1212

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

2525
{
2626
batch := Batch{
27-
Groups: map[string][]string{
27+
Groups: map[string]Group{
2828
"$a": {"$b"},
2929
"$b": {"$a"},
3030
},
@@ -43,10 +43,10 @@ func TestBatchFiles(t *testing.T) {
4343
g.WriteFile(filepath.FromSlash(p), "hello world!")
4444

4545
batch := Batch{
46-
Files: map[string][]string{
46+
Files: map[string]Group{
4747
p: {"$c", "d"},
4848
},
49-
Groups: map[string][]string{
49+
Groups: map[string]Group{
5050
"$a": {"a", "b"},
5151
"$b": {"c", "$a"},
5252
"$c": {"$b"},

lib/whisper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
const (
15-
APIVersion = "v0.8.9"
15+
APIVersion = "v0.8.10"
1616
WireFormatVersion = byte(8)
1717
)
1818

0 commit comments

Comments
 (0)