Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 14 additions & 31 deletions cmd/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ func completeGroups(cfg *config.Config) []string {
return names
}

func repoGroupCompleter(cfgPath *string) func(context.Context, *cli.Command) {
func makeCompleter(
cfgPath *string,
getters ...func(*config.Config) []string,
) func(context.Context, *cli.Command) {
return func(_ context.Context, cmd *cli.Command) {
cfg, err := config.Load(*cfgPath)
if err != nil {
Expand All @@ -42,42 +45,22 @@ func repoGroupCompleter(cfgPath *string) func(context.Context, *cli.Command) {

w := cmd.Root().Writer

for _, name := range completeRepos(&cfg) {
_, _ = fmt.Fprintln(w, name)
}

for _, name := range completeGroups(&cfg) {
_, _ = fmt.Fprintln(w, name)
for _, get := range getters {
for _, name := range get(&cfg) {
_, _ = fmt.Fprintln(w, name)
}
}
}
}

func reposOnlyCompleter(cfgPath *string) func(context.Context, *cli.Command) {
return func(_ context.Context, cmd *cli.Command) {
cfg, err := config.Load(*cfgPath)
if err != nil {
return
}

w := cmd.Root().Writer
func repoGroupCompleter(cfgPath *string) func(context.Context, *cli.Command) {
return makeCompleter(cfgPath, completeRepos, completeGroups)
}

for _, name := range completeRepos(&cfg) {
_, _ = fmt.Fprintln(w, name)
}
}
func reposOnlyCompleter(cfgPath *string) func(context.Context, *cli.Command) {
return makeCompleter(cfgPath, completeRepos)
}

func groupsOnlyCompleter(cfgPath *string) func(context.Context, *cli.Command) {
return func(_ context.Context, cmd *cli.Command) {
cfg, err := config.Load(*cfgPath)
if err != nil {
return
}

w := cmd.Root().Writer

for _, name := range completeGroups(&cfg) {
_, _ = fmt.Fprintln(w, name)
}
}
return makeCompleter(cfgPath, completeGroups)
}
9 changes: 7 additions & 2 deletions cmd/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
Usage: "add the repo(s) to this group",
},
},
Action: repoAddAction(cfgPath),
ShellComplete: func(_ context.Context, _ *cli.Command) {},

Check failure on line 65 in cmd/repo.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a nested comment explaining why this function is empty or complete the implementation.

See more on https://sonarcloud.io/project/issues?id=hugoh_hrd&issues=AZ8QHOmvqjbo_uOAtf3z&open=AZ8QHOmvqjbo_uOAtf3z&pullRequest=42
Action: repoAddAction(cfgPath),
}
}

Expand Down Expand Up @@ -125,7 +126,11 @@
cfg.AddRepoToGroup(name, group)
}

ui.Success("added %s as %q", abs, name)
if group != "" {
ui.Success("added %s as %q in group %s", abs, name, group)
} else {
ui.Success("added %s as %q", abs, name)
}

return nil
}
Expand Down
Loading
Loading