-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_openshift_bash_comp.go
60 lines (51 loc) · 1.42 KB
/
gen_openshift_bash_comp.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
package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/openshift/origin/pkg/cmd/admin"
"github.com/openshift/origin/pkg/cmd/cli"
"github.com/openshift/origin/pkg/cmd/openshift"
)
func OutDir(path string) (string, error) {
outDir, err := filepath.Abs(path)
if err != nil {
return "", err
}
stat, err := os.Stat(outDir)
if err != nil {
return "", err
}
if !stat.IsDir() {
return "", fmt.Errorf("output directory %s is not a directory\n", outDir)
}
outDir = outDir + "/"
return outDir, nil
}
func main() {
// use os.Args instead of "flags" because "flags" will mess up the man pages!
path := "contrib/completions/bash/"
if len(os.Args) == 2 {
path = os.Args[1]
} else if len(os.Args) > 2 {
fmt.Fprintf(os.Stderr, "usage: %s [output directory]\n", os.Args[0])
os.Exit(1)
}
outDir, err := OutDir(path)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to get output directory: %v\n", err)
os.Exit(1)
}
outFile_openshift := outDir + "openshift"
openshift := openshift.NewCommandOpenShift("openshift")
openshift.GenBashCompletionFile(outFile_openshift)
outFile_osc := outDir + "oc"
out := os.Stdout
oc := cli.NewCommandCLI("oc", "openshift cli", &bytes.Buffer{}, out, ioutil.Discard)
oc.GenBashCompletionFile(outFile_osc)
outFile_osadm := outDir + "oadm"
oadm := admin.NewCommandAdmin("oadm", "openshift admin", ioutil.Discard)
oadm.GenBashCompletionFile(outFile_osadm)
}