...

Source file src/k8s.io/kubernetes/cmd/gendocs/gen_kubectl_docs.go

Documentation: k8s.io/kubernetes/cmd/gendocs

     1  /*
     2  Copyright 2014 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package main
    18  
    19  import (
    20  	"bytes"
    21  	"fmt"
    22  	"io"
    23  	"os"
    24  
    25  	"github.com/spf13/cobra/doc"
    26  	"k8s.io/cli-runtime/pkg/genericiooptions"
    27  	"k8s.io/kubectl/pkg/cmd"
    28  	"k8s.io/kubernetes/cmd/genutils"
    29  )
    30  
    31  func main() {
    32  	// use os.Args instead of "flags" because "flags" will mess up the man pages!
    33  	path := "docs/"
    34  	if len(os.Args) == 2 {
    35  		path = os.Args[1]
    36  	} else if len(os.Args) > 2 {
    37  		fmt.Fprintf(os.Stderr, "usage: %s [output directory]\n", os.Args[0])
    38  		os.Exit(1)
    39  	}
    40  
    41  	outDir, err := genutils.OutDir(path)
    42  	if err != nil {
    43  		fmt.Fprintf(os.Stderr, "failed to get output directory: %v\n", err)
    44  		os.Exit(1)
    45  	}
    46  
    47  	// Set environment variables used by kubectl so the output is consistent,
    48  	// regardless of where we run.
    49  	os.Setenv("HOME", "/home/username")
    50  	kubectl := cmd.NewKubectlCommand(cmd.KubectlOptions{IOStreams: genericiooptions.IOStreams{In: bytes.NewReader(nil), Out: io.Discard, ErrOut: io.Discard}})
    51  	doc.GenMarkdownTree(kubectl, outDir)
    52  }
    53  

View as plain text