Skip to content

Commit

Permalink
magefiles: add gen:completions
Browse files Browse the repository at this point in the history
  • Loading branch information
jzelinskie committed Feb 29, 2024
1 parent 76f31d3 commit eb5a4a1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist/
completions/
*.wasm
.vscode/settings.json
.env.local
20 changes: 20 additions & 0 deletions magefiles/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main

import (
"fmt"
"os"

"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
Expand All @@ -29,3 +30,22 @@ func (Gen) Proto() error {
return RunSh("go", Tool())("run", "github.com/bufbuild/buf/cmd/buf",
"generate", "-o", "../pkg/proto", "../proto/internal", "--template", "../buf.gen.yaml")
}

func (Gen) Completions() error {
if err := RunSh("mkdir", WithDir("."))("-p", "./completions"); err != nil {
return err
}

for _, shell := range []string{"bash", "zsh", "fish"} {
f, err := os.Create("./completions/spicedb." + shell)
if err != nil {
return err
}
defer f.Close()

if err := RunSh("go", WithDir("."), WithStdout(f))("run", "./cmd/spicedb/main.go", "completion", shell); err != nil {
return err
}
}
return nil
}

0 comments on commit eb5a4a1

Please sign in to comment.