Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/cli/init.go: make flag help consistent #1564

Merged
merged 1 commit into from
Jun 18, 2020
Merged
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
9 changes: 8 additions & 1 deletion pkg/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"log"
"os"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -100,18 +101,24 @@ func (c cli) getAvailableProjectVersions() (projectVersions []string) {
for version := range versionSet {
projectVersions = append(projectVersions, strconv.Quote(version))
}
sort.Strings(projectVersions)
return projectVersions
}

func (c cli) getAvailablePlugins() (pluginKeys []string) {
keySet := make(map[string]struct{})
for _, versionedPlugins := range c.pluginsFromOptions {
for _, p := range versionedPlugins {
// Only return non-deprecated plugins.
if _, isDeprecated := p.(plugin.Deprecated); !isDeprecated {
pluginKeys = append(pluginKeys, strconv.Quote(plugin.KeyFor(p)))
keySet[plugin.KeyFor(p)] = struct{}{}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see that we're doing sort.Strings(pluginKeys) which orders the plugin keys but any reason for building the keySet here and then appending the keys to pluginKeys?
pluginKeys = append(pluginKeys, strconv.Quote(plugin.KeyFor(p))) isn't too unreadable imo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c.pluginsFromOptions are indexed by project version, so two versionedPlugins slices can be intersecting sets if one plugin supports two project versions (go/v2 supports project versions 2 and 3-alpha).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, double counting. Gotcha.

}
}
}
for key := range keySet {
pluginKeys = append(pluginKeys, strconv.Quote(key))
}
sort.Strings(pluginKeys)
return pluginKeys
}

Expand Down