mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 10:00:56 +00:00
mdtogo: support for alternate license headers
This commit is contained in:
@@ -12,7 +12,7 @@ linters:
|
|||||||
- bodyclose
|
- bodyclose
|
||||||
- deadcode
|
- deadcode
|
||||||
- depguard
|
- depguard
|
||||||
- dogsled
|
# - dogsled
|
||||||
- dupl
|
- dupl
|
||||||
# - errcheck
|
# - errcheck
|
||||||
# - funlen
|
# - funlen
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
// Copyright 2019 The Kubernetes Authors.
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
//go:generate $GOBIN/mdtogo docs/api-conventions cmddocs/api --full=true
|
//go:generate $GOBIN/mdtogo docs/api-conventions cmddocs/api --full=true --license=none
|
||||||
//go:generate $GOBIN/mdtogo docs/commands cmddocs/commands
|
//go:generate $GOBIN/mdtogo docs/commands cmddocs/commands --license=none
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
// Package main generates cobra.Command go variables containing documentation read from .md files.
|
// 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
|
// 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/
|
// used by cobra commands for documentation.The variable names are generated from the SOURCE_MD_DIR/
|
||||||
@@ -28,6 +28,13 @@
|
|||||||
// ## cmd
|
// ## cmd
|
||||||
//
|
//
|
||||||
// All sections will be parsed into a Long string.
|
// 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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -42,12 +49,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var full bool
|
var full bool
|
||||||
|
var licenseFile string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
for _, a := range os.Args {
|
for _, a := range os.Args {
|
||||||
if a == "--full=true" {
|
if a == "--full=true" {
|
||||||
full = true
|
full = true
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(a, "--license=") {
|
||||||
|
licenseFile = strings.ReplaceAll(a, "--license=", "")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(os.Args) < 3 {
|
if len(os.Args) < 3 {
|
||||||
@@ -77,9 +88,23 @@ func main() {
|
|||||||
docs = append(docs, parse(f.Name(), string(b)))
|
docs = append(docs, parse(f.Name(), string(b)))
|
||||||
}
|
}
|
||||||
|
|
||||||
out := []string{`// Copyright 2019 The Kubernetes Authors.
|
var license string
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
|
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.
|
// Code generated by "mdtogo"; DO NOT EDIT.
|
||||||
package ` + filepath.Base(dest) + "\n"}
|
package ` + filepath.Base(dest) + "\n"}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user