Skip to content

Commit

Permalink
Filter users and projects to contain only unique values
Browse files Browse the repository at this point in the history
  • Loading branch information
berlam committed Oct 4, 2019
1 parent e5e2683 commit aa8d99c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func init() {
showBcsCmd.MarkFlagRequired(internal.FlagReport)

showJiraCmd.Flags().StringArrayVar(&conf.Projects, internal.FlagProjects, nil, "specify the project key")
showJiraCmd.Flags().StringArrayVar(&conf.Users, internal.FlagUsers, nil, "show results for user")
showJiraCmd.Flags().StringArrayVar(&conf.Users, internal.FlagUsers, nil, "show results for user (or user=id, where id is the account id)")
}

var showCmd = &cobra.Command{
Expand Down
27 changes: 20 additions & 7 deletions pkg/timesheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,39 @@ type User struct {
}

func Projects(projects []string) []Project {
result := make([]Project, len(projects))
for i, project := range projects {
result[i] = Project(project)
mapping := make(map[string]Project)
for _, project := range projects {
mapping[project] = Project(project)
}
i := 0
result := make([]Project, len(mapping))
for _, project := range mapping {
result[i] = project
i++
}
return result
}

func Users(users []string) []*User {
result := make([]*User, len(users))
for i, user := range users {
mapping := make(map[string]*User)
for _, user := range users {
parts := strings.SplitN(user, "=", 2)
name := parts[0]
id := ""
if len(parts) == 2 {
id = parts[1]
}
result[i] = &User{
DisplayName: parts[0],
mapping[name] = &User{
DisplayName: name,
Id: id,
}
}
i := 0
result := make([]*User, len(mapping))
for _, v := range mapping {
result[i] = v
i++
}
return result
}

Expand Down

0 comments on commit aa8d99c

Please sign in to comment.