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

generate: fix external usage #1476

Merged
merged 1 commit into from
Jan 13, 2023
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
5 changes: 5 additions & 0 deletions cmd/carapace/cmd/completers/completers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
"gopkg.in/yaml.v3"
)

var (
descriptions = make(map[string]string)
names = make([]string, 0)
)

func Names() []string {
unique := make(map[string]string)
for _, name := range names {
Expand Down
8 changes: 4 additions & 4 deletions cmd/generate/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {

formattedNames := make([]string, 0)
for _, name := range names {
formattedNames = append(formattedNames, fmt.Sprintf("\t\"%v\",", name))
formattedNames = append(formattedNames, fmt.Sprintf(" \"%v\",", name))
}

maxlen := 0
Expand All @@ -40,7 +40,7 @@ func main() {

formattedDescriptions := make([]string, 0)
for _, name := range names {
formattedDescriptions = append(formattedDescriptions, fmt.Sprintf(` %--`+strconv.Itoa(maxlen+4)+`v"%v",`, fmt.Sprintf(`"%v": `, name), descriptions[name]))
formattedDescriptions = append(formattedDescriptions, fmt.Sprintf(` %--`+strconv.Itoa(maxlen+4)+`v"%v",`, fmt.Sprintf(`"%v": `, name), descriptions[name]))
}

cases := make([]string, 0)
Expand Down Expand Up @@ -73,8 +73,8 @@ func executeCompleter(completer string) {

os.Mkdir(root+"/cmd/carapace/cmd/completers", 0755)
os.WriteFile(root+"/cmd/carapace/cmd/completers.go", []byte("//go:build !release\n\n"+content), 0644)
os.WriteFile(root+"/cmd/carapace/cmd/completers/name.go", []byte(fmt.Sprintf("package completers\n\nvar names = []string{\n%v\n}\n", strings.Join(formattedNames, "\n"))), 0644)
os.WriteFile(root+"/cmd/carapace/cmd/completers/description.go", []byte(fmt.Sprintf("package completers\n\nvar descriptions = map[string]string{\n%v\n}\n", strings.Join(formattedDescriptions, "\n"))), 0644)
os.WriteFile(root+"/cmd/carapace/cmd/completers/name.go", []byte(fmt.Sprintf("package completers\n\nfunc init() {\n names = []string{\n%v\n\t}\n}\n", strings.Join(formattedNames, "\n"))), 0644)
os.WriteFile(root+"/cmd/carapace/cmd/completers/description.go", []byte(fmt.Sprintf("package completers\n\nfunc init() {\n descriptions = map[string]string{\n%v\n\t}\n}\n", strings.Join(formattedDescriptions, "\n"))), 0644)
os.WriteFile(root+"/cmd/carapace/cmd/completers_release.go", []byte("//go:build release\n\n"+strings.Replace(content, "/completers/", "/completers_release/", -1)), 0644)
os.RemoveAll(root + "/completers_release")
execabs.Command("cp", "-r", root+"/completers", root+"/completers_release").Run()
Expand Down