diff --git a/cmd/config/.golangci.yml b/cmd/config/.golangci.yml index 4b800e332..63db8666e 100644 --- a/cmd/config/.golangci.yml +++ b/cmd/config/.golangci.yml @@ -12,7 +12,7 @@ linters: - bodyclose - deadcode - depguard - - dogsled +# - dogsled - dupl # - errcheck # - funlen diff --git a/cmd/config/main.go b/cmd/config/main.go index 520fe7f97..1c96ac3e1 100644 --- a/cmd/config/main.go +++ b/cmd/config/main.go @@ -1,8 +1,8 @@ // Copyright 2019 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0 -//go:generate $GOBIN/mdtogo docs/api-conventions cmddocs/api --full=true -//go:generate $GOBIN/mdtogo docs/commands cmddocs/commands +//go:generate $GOBIN/mdtogo docs/api-conventions cmddocs/api --full=true --license=none +//go:generate $GOBIN/mdtogo docs/commands cmddocs/commands --license=none package main import ( diff --git a/cmd/mdtogo/main.go b/cmd/mdtogo/main.go index 6d7609ef3..9b3d41f50 100644 --- a/cmd/mdtogo/main.go +++ b/cmd/mdtogo/main.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Package main generates cobra.Command go variables containing documentation read from .md files. -// Usage: mdtogo SOURCE_MD_DIR/ DEST_GO_DIR/ [--full=true] +// Usage: mdtogo SOURCE_MD_DIR/ DEST_GO_DIR/ [--full=true] [--license=license.txt|none] // // The command will create a docs.go file under DEST_GO_DIR/ containing string variables to be // used by cobra commands for documentation.The variable names are generated from the SOURCE_MD_DIR/ @@ -28,6 +28,13 @@ // ## cmd // // All sections will be parsed into a Long string. +// +// Flags: +// --full=true +// Create a Long variable from the full .md files, rather than separate sections. +// --license +// Controls the license header added to the files. Specify a path to a license file, +// or "none" to skip adding a license. package main import ( @@ -42,12 +49,16 @@ import ( ) var full bool +var licenseFile string func main() { for _, a := range os.Args { if a == "--full=true" { full = true } + if strings.HasPrefix(a, "--license=") { + licenseFile = strings.ReplaceAll(a, "--license=", "") + } } if len(os.Args) < 3 { @@ -77,9 +88,23 @@ func main() { docs = append(docs, parse(f.Name(), string(b))) } - out := []string{`// Copyright 2019 The Kubernetes Authors. -// SPDX-License-Identifier: Apache-2.0 + var license string + if licenseFile == "" { + license = `// Copyright 2019 The Kubernetes Authors. +// SPDX-License-Identifier: Apache-2.0` + } else if licenseFile == "none" { + // no license -- maybe added by another tool + } else { + b, err := ioutil.ReadFile(licenseFile) + if err != nil { + fmt.Fprintf(os.Stderr, "%v\n", err) + os.Exit(1) + } + license = string(b) + } + + out := []string{license, ` // Code generated by "mdtogo"; DO NOT EDIT. package ` + filepath.Base(dest) + "\n"}