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,8 +20,8 @@ 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"
"github.com/spf13/cobra"
@@ -29,36 +29,24 @@ import (
func main() {
// use os.Args instead of "flags" because "flags" will mess up the man pages!
docsDir := "docs/man/man1/"
path := "docs/"
if len(os.Args) == 2 {
docsDir = 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])
return
os.Exit(1)
}
docsDir, err := filepath.Abs(docsDir)
outDir, err := genutils.OutDir(path)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
return
fmt.Fprintf(os.Stderr, "failed to get output directory: %v\n", err)
os.Exit(1)
}
stat, err := os.Stat(docsDir)
if err != nil {
fmt.Fprintf(os.Stderr, "output directory %s does not exist\n", docsDir)
return
}
if !stat.IsDir() {
fmt.Fprintf(os.Stderr, "output directory %s is not a directory\n", docsDir)
return
}
docsDir = docsDir + "/"
// Set environment variables used by kubectl so the output is consistent,
// regardless of where we run.
os.Setenv("HOME", "/home/username")
//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)
cobra.GenMarkdownTree(kubectl, docsDir)
cobra.GenMarkdownTree(kubectl, outDir)
}