doc/bash completions autogeneration directory helper

This commit is contained in:
Eric Paris
2015-04-12 13:25:50 -04:00
parent ebb0affc21
commit 55d133eabb
5 changed files with 104 additions and 56 deletions

View File

@@ -20,39 +20,28 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/GoogleCloudPlatform/kubernetes/cmd/genutils"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
cmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
)
func main() {
// use os.Args instead of "flags" because "flags" will mess up the man pages!
outDir := "contrib/completions/bash/"
path := "contrib/completions/bash/"
if len(os.Args) == 2 {
outDir = os.Args[1]
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 := filepath.Abs(outDir)
outDir, err := genutils.OutDir(path)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
fmt.Fprintf(os.Stderr, "failed to get output directory: %v\n", err)
os.Exit(1)
}
stat, err := os.Stat(outDir)
if err != nil {
fmt.Fprintf(os.Stderr, "output directory %s does not exist\n", outDir)
os.Exit(1)
}
if !stat.IsDir() {
fmt.Fprintf(os.Stderr, "output directory %s is not a directory\n", outDir)
os.Exit(1)
}
outFile := outDir + "/kubectl"
outFile := outDir + "kubectl"
//TODO os.Stdin should really be something like ioutil.Discard, but a Reader
kubectl := cmd.NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, ioutil.Discard, ioutil.Discard)