Skip to content

Commit 588ea92

Browse files
committed
Remove duplication
Signed-off-by: David Gageot <david.gageot@docker.com>
1 parent 54f2bf6 commit 588ea92

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

pkg/team/team.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ func WithAgents(agents ...*agent.Agent) Opt {
3232
}
3333

3434
func New(opts ...Opt) *Team {
35-
t := &Team{agents: make(map[string]*agent.Agent)}
35+
t := &Team{
36+
agents: make(map[string]*agent.Agent),
37+
}
3638
for _, opt := range opts {
3739
opt(t)
3840
}
@@ -49,18 +51,13 @@ func (t *Team) AgentNames() []string {
4951
}
5052

5153
func (t *Team) Agent(name string) (*agent.Agent, error) {
52-
if len(t.agents) == 0 {
54+
if t.Size() == 0 {
5355
return nil, errors.New("no agents loaded; ensure your agent configuration defines at least one agent")
5456
}
5557

5658
found, ok := t.agents[name]
5759
if !ok {
58-
var names []string
59-
for n := range t.agents {
60-
names = append(names, n)
61-
}
62-
63-
return nil, fmt.Errorf("agent not found: %s (available agents: %s)", name, strings.Join(names, ", "))
60+
return nil, fmt.Errorf("agent not found: %s (available agents: %s)", name, strings.Join(t.AgentNames(), ", "))
6461
}
6562

6663
return found, nil

0 commit comments

Comments
 (0)