-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
67 lines (52 loc) · 1.2 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"bytes"
"io"
"os"
"path/filepath"
"time"
"github.com/gabe565/castsponsorskip/cmd"
flag "github.com/spf13/pflag"
)
var Shells = []string{"bash", "zsh", "fish"}
func main() {
flags := flag.NewFlagSet("", flag.ContinueOnError)
var dateParam string
flags.StringVar(&dateParam, "date", time.Now().Format(time.RFC3339), "Build date")
if err := flags.Parse(os.Args); err != nil {
panic(err)
}
date, err := time.Parse(time.RFC3339, dateParam)
if err != nil {
panic(err)
}
if err := os.RemoveAll("completions"); err != nil {
panic(err)
}
if err := os.MkdirAll("completions", 0o777); err != nil {
panic(err)
}
rootCmd := cmd.NewCommand("latest", "")
name := rootCmd.Name()
var buf bytes.Buffer
rootCmd.SetOut(&buf)
for _, shell := range Shells {
rootCmd.SetArgs([]string{"--completion=" + shell})
if err := rootCmd.Execute(); err != nil {
panic(err)
}
f, err := os.Create(filepath.Join("completions", name+"."+shell))
if err != nil {
panic(err)
}
if _, err := io.Copy(f, &buf); err != nil {
panic(err)
}
if err := f.Close(); err != nil {
panic(err)
}
if err := os.Chtimes(f.Name(), date, date); err != nil {
panic(err)
}
}
}