Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dist/
temp/
docs/merged.md
completions/

# Local-only files
go.work
Expand Down
17 changes: 17 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
version: 2
before:
hooks:
- "go run mage.go gen:completions"
builds:
- id: "linux-amd64-gnu"
goos: ["linux"]
Expand Down Expand Up @@ -108,6 +111,19 @@ nfpms:
epoch: &epoch "0"
ids: ["linux-amd64-gnu", "linux-arm64-gnu"]
formats: ["deb", "rpm"]
contents: &nfpm_contents
- src: "./completions/zed.bash"
dst: "/usr/share/bash-completion/completions/zed"
file_info:
mode: 0644
- src: "./completions/zed.fish"
dst: "/usr/share/fish/vendor_completions.d/zed.fish"
file_info:
mode: 0644
- src: "./completions/zed.zsh"
dst: "/usr/share/zsh/site-functions/_zed"
file_info:
mode: 0644
- id: "musl"
vendor: *vendor
homepage: *homepage
Expand All @@ -117,6 +133,7 @@ nfpms:
epoch: *epoch
ids: ["linux-amd64-musl", "linux-arm64-musl"]
formats: ["apk"]
contents: *nfpm_contents

furies:
- account: "authzed"
Expand Down
39 changes: 39 additions & 0 deletions magefiles/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
package main

import (
"io"
"os"
"path/filepath"

"github.com/jzelinskie/cobrautil/v2/cobrazerolog"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"github.com/spf13/cobra"

"github.com/authzed/zed/internal/cmd"
)
Expand Down Expand Up @@ -47,3 +50,39 @@ func (g Gen) DocsForPublish() error {

return sh.RunV("bash", "-c", "cat docs/getting-started.md <(echo -e '\\n') docs/zed.md > docs/merged.md")
}

// Completions Generate shell completion scripts for bash, zsh, and fish
func (g Gen) Completions() error {
targetDir := "completions"

if err := os.MkdirAll(targetDir, 0o755); err != nil {
return err
}

rootCmd := cmd.InitialiseRootCmd(cobrazerolog.New())
Comment thread
ivanauth marked this conversation as resolved.
Outdated

generators := []struct {
shell string
generate func(*cobra.Command, io.Writer) error
}{
{"bash", func(c *cobra.Command, w io.Writer) error { return c.GenBashCompletionV2(w, true) }},
{"zsh", func(c *cobra.Command, w io.Writer) error { return c.GenZshCompletion(w) }},
{"fish", func(c *cobra.Command, w io.Writer) error { return c.GenFishCompletion(w, true) }},
}

for _, gen := range generators {
path := filepath.Join(targetDir, "zed."+gen.shell)
f, err := os.Create(path)
if err != nil {
return err
}
if err := gen.generate(rootCmd, f); err != nil {
f.Close()
return err
}
if err := f.Close(); err != nil {
return err
}
}
return nil
}
Loading