gendocs: using bytes.NewReader(nil)/ioutil.Discard instead of os input/output to generate command

This commit is contained in:
SataQiu 2021-06-08 11:55:32 +08:00
parent 588d984407
commit aea2e33175
3 changed files with 8 additions and 7 deletions

View File

@ -17,6 +17,7 @@ limitations under the License.
package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
@ -45,7 +46,6 @@ func main() {
// 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(os.Stdin, ioutil.Discard, ioutil.Discard)
kubectl := cmd.NewKubectlCommand(bytes.NewReader(nil), ioutil.Discard, ioutil.Discard)
doc.GenMarkdownTree(kubectl, outDir)
}

View File

@ -17,7 +17,9 @@ limitations under the License.
package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"github.com/spf13/cobra/doc"
@ -77,7 +79,7 @@ func main() {
pflag.CommandLine = pflag.NewFlagSet(os.Args[0], pflag.ExitOnError)
// generate docs for kubeadm
kubeadm := kubeadmapp.NewKubeadmCommand(os.Stdin, os.Stdout, os.Stderr)
kubeadm := kubeadmapp.NewKubeadmCommand(bytes.NewReader(nil), ioutil.Discard, ioutil.Discard)
doc.GenMarkdownTree(kubeadm, outDir)
// cleanup generated code for usage as include in the website

View File

@ -96,15 +96,14 @@ func main() {
}
case "kubectl":
// generate manpage for kubectl
// TODO os.Stdin should really be something like ioutil.Discard, but a Reader
kubectl := kubectlcmd.NewKubectlCommand(os.Stdin, ioutil.Discard, ioutil.Discard)
kubectl := kubectlcmd.NewKubectlCommand(bytes.NewReader(nil), ioutil.Discard, ioutil.Discard)
genMarkdown(kubectl, "", outDir)
for _, c := range kubectl.Commands() {
genMarkdown(c, "kubectl", outDir)
}
case "kubeadm":
// generate manpage for kubelet
kubeadm := kubeadmapp.NewKubeadmCommand(os.Stdin, os.Stdout, os.Stderr)
// generate manpage for kubeadm
kubeadm := kubeadmapp.NewKubeadmCommand(bytes.NewReader(nil), ioutil.Discard, ioutil.Discard)
genMarkdown(kubeadm, "", outDir)
for _, c := range kubeadm.Commands() {
genMarkdown(c, "kubeadm", outDir)