Skip to content

Commit

Permalink
generate: fix external usage
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jan 13, 2023
1 parent ca3c18f commit 8fad444
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
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

0 comments on commit 8fad444

Please sign in to comment.