mirror of https://github.com/kubernetes/kops.git
Bump heredoc to v2
This commit is contained in:
parent
52ea87d6ba
commit
dadd752574
2
go.mod
2
go.mod
|
@ -53,7 +53,7 @@ require (
|
|||
cloud.google.com/go v0.54.0
|
||||
github.com/Azure/azure-pipeline-go v0.2.3
|
||||
github.com/Azure/azure-storage-blob-go v0.10.0
|
||||
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd
|
||||
github.com/MakeNowJust/heredoc/v2 v2.0.1
|
||||
github.com/Masterminds/sprig/v3 v3.1.0
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.264
|
||||
github.com/aws/amazon-ec2-instance-selector/v2 v2.0.1
|
||||
|
|
2
go.sum
2
go.sum
|
@ -76,6 +76,8 @@ github.com/GoogleCloudPlatform/k8s-cloud-provider v0.0.0-20200415212048-7901bc82
|
|||
github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab/go.mod h1:3VYc5hodBMJ5+l/7J4xAyMeuM2PNuepvHlGs8yilUCA=
|
||||
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd h1:sjQovDkwrZp8u+gxLtPgKGjk5hCxuy2hrRejBTA9xFU=
|
||||
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd/go.mod h1:64YHyfSL2R96J44Nlwm39UHepQbyR5q10x7iYa1ks2E=
|
||||
github.com/MakeNowJust/heredoc/v2 v2.0.1 h1:rlCHh70XXXv7toz95ajQWOWQnN4WNLt0TdpZYIR/J6A=
|
||||
github.com/MakeNowJust/heredoc/v2 v2.0.1/go.mod h1:6/2Abh5s+hc3g9nbWLe9ObDIOhaRrqsyY9MWy+4JdRM=
|
||||
github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg=
|
||||
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
|
||||
github.com/Masterminds/semver/v3 v3.1.0 h1:Y2lUDsFKVRSYGojLJ1yLxSXdMmMYTYls0rCvoqmMUQk=
|
||||
|
|
|
@ -19,7 +19,7 @@ go_test(
|
|||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//pkg/apis/kops/v1alpha2:go_default_library",
|
||||
"//vendor/github.com/MakeNowJust/heredoc:go_default_library",
|
||||
"//vendor/github.com/MakeNowJust/heredoc/v2:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
],
|
||||
|
|
|
@ -20,7 +20,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/MakeNowJust/heredoc"
|
||||
"github.com/MakeNowJust/heredoc/v2"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
|
|
@ -11,5 +11,5 @@ go_test(
|
|||
name = "go_default_test",
|
||||
srcs = ["streamwriter_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = ["//vendor/github.com/MakeNowJust/heredoc:go_default_library"],
|
||||
deps = ["//vendor/github.com/MakeNowJust/heredoc/v2:go_default_library"],
|
||||
)
|
||||
|
|
|
@ -23,7 +23,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/MakeNowJust/heredoc"
|
||||
"github.com/MakeNowJust/heredoc/v2"
|
||||
)
|
||||
|
||||
func TestWriteToken(t *testing.T) {
|
||||
|
|
|
@ -21,7 +21,7 @@ go_test(
|
|||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//pkg/diff:go_default_library",
|
||||
"//vendor/github.com/MakeNowJust/heredoc:go_default_library",
|
||||
"//vendor/github.com/MakeNowJust/heredoc/v2:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/MakeNowJust/heredoc"
|
||||
"github.com/MakeNowJust/heredoc/v2"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
|
|
@ -24,7 +24,7 @@ go_test(
|
|||
deps = [
|
||||
"//pkg/apis/kops/v1alpha2:go_default_library",
|
||||
"//pkg/diff:go_default_library",
|
||||
"//vendor/github.com/MakeNowJust/heredoc:go_default_library",
|
||||
"//vendor/github.com/MakeNowJust/heredoc/v2:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
],
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/MakeNowJust/heredoc"
|
||||
"github.com/MakeNowJust/heredoc/v2"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/kops/pkg/apis/kops/v1alpha2"
|
||||
|
|
|
@ -5,7 +5,7 @@ go_library(
|
|||
srcs = ["help.go"],
|
||||
importpath = "k8s.io/kops/pkg/pretty",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//vendor/github.com/MakeNowJust/heredoc:go_default_library"],
|
||||
deps = ["//vendor/github.com/MakeNowJust/heredoc/v2:go_default_library"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
|
|
|
@ -20,7 +20,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/MakeNowJust/heredoc"
|
||||
"github.com/MakeNowJust/heredoc/v2"
|
||||
)
|
||||
|
||||
// Bash markdown-quotes a bash command for insertion into help text.
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["heredoc.go"],
|
||||
importmap = "k8s.io/kops/vendor/github.com/MakeNowJust/heredoc/v2",
|
||||
importpath = "github.com/MakeNowJust/heredoc/v2",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2019 TSUYUSATO Kitsune
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -0,0 +1,48 @@
|
|||
# heredoc
|
||||
|
||||
[](https://github.com/MakeNowJust/heredoc/releases)
|
||||
[](https://circleci.com/gh/MakeNowJust/heredoc)
|
||||
[](https://godoc.org/github.com/MakeNowJust/heredoc)
|
||||
|
||||
## About
|
||||
|
||||
Package heredoc provides the here-document with keeping indent.
|
||||
|
||||
## Import
|
||||
|
||||
```go
|
||||
import "github.com/MakeNowJust/heredoc/v2"
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/MakeNowJust/heredoc/v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(heredoc.Doc(`
|
||||
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
|
||||
sed do eiusmod tempor incididunt ut labore et dolore magna
|
||||
aliqua. Ut enim ad minim veniam, ...
|
||||
`))
|
||||
// Output:
|
||||
// Lorem ipsum dolor sit amet, consectetur adipisicing elit,
|
||||
// sed do eiusmod tempor incididunt ut labore et dolore magna
|
||||
// aliqua. Ut enim ad minim veniam, ...
|
||||
//
|
||||
}
|
||||
```
|
||||
|
||||
## API Document
|
||||
|
||||
- [heredoc - GoDoc](https://godoc.org/github.com/MakeNowJust/heredoc)
|
||||
|
||||
## License
|
||||
|
||||
This software is released under the MIT License, see LICENSE.
|
|
@ -0,0 +1,3 @@
|
|||
module github.com/MakeNowJust/heredoc/v2
|
||||
|
||||
go 1.12
|
|
@ -0,0 +1,118 @@
|
|||
// Copyright (c) 2014-2019 TSUYUSATO Kitsune
|
||||
// This software is released under the MIT License.
|
||||
// http://opensource.org/licenses/mit-license.php
|
||||
|
||||
// Package heredoc provides creation of here-documents from raw strings.
|
||||
//
|
||||
// Golang supports raw-string syntax.
|
||||
//
|
||||
// doc := `
|
||||
// Foo
|
||||
// Bar
|
||||
// `
|
||||
//
|
||||
// But raw-string cannot recognize indentation. Thus such content is an indented string, equivalent to
|
||||
//
|
||||
// "\n\tFoo\n\tBar\n"
|
||||
//
|
||||
// I dont't want this!
|
||||
//
|
||||
// However this problem is solved by package heredoc.
|
||||
//
|
||||
// doc := heredoc.Doc(`
|
||||
// Foo
|
||||
// Bar
|
||||
// `)
|
||||
//
|
||||
// Is equivalent to
|
||||
//
|
||||
// "Foo\nBar\n"
|
||||
package heredoc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const maxInt = int(^uint(0) >> 1)
|
||||
|
||||
// Doc returns un-indented string as here-document.
|
||||
func Doc(raw string) string {
|
||||
skipFirstLine := false
|
||||
if len(raw) > 0 && raw[0] == '\n' {
|
||||
raw = raw[1:]
|
||||
} else {
|
||||
skipFirstLine = true
|
||||
}
|
||||
|
||||
lines := strings.Split(raw, "\n")
|
||||
|
||||
minIndentSize := getMinIndent(lines, skipFirstLine)
|
||||
lines = removeIndentation(lines, minIndentSize, skipFirstLine)
|
||||
|
||||
return strings.Join(lines, "\n")
|
||||
}
|
||||
|
||||
// isSpace checks whether the rune represents space or not.
|
||||
// Only white spcaes (U+0020) and horizontal tabs are treated as space character.
|
||||
// It is the same as Go.
|
||||
//
|
||||
// See https://github.com/MakeNowJust/heredoc/issues/6#issuecomment-524231625.
|
||||
func isSpace(r rune) bool {
|
||||
switch r {
|
||||
case ' ', '\t':
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// getMinIndent calculates the minimum indentation in lines, excluding empty lines.
|
||||
func getMinIndent(lines []string, skipFirstLine bool) int {
|
||||
minIndentSize := maxInt
|
||||
|
||||
for i, line := range lines {
|
||||
if i == 0 && skipFirstLine {
|
||||
continue
|
||||
}
|
||||
|
||||
indentSize := 0
|
||||
for _, r := range line {
|
||||
if isSpace(r) {
|
||||
indentSize++
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if len(line) == indentSize {
|
||||
if i == len(lines)-1 && indentSize < minIndentSize {
|
||||
lines[i] = ""
|
||||
}
|
||||
} else if indentSize < minIndentSize {
|
||||
minIndentSize = indentSize
|
||||
}
|
||||
}
|
||||
return minIndentSize
|
||||
}
|
||||
|
||||
// removeIndentation removes n characters from the front of each line in lines.
|
||||
// Skips first line if skipFirstLine is true, skips empty lines.
|
||||
func removeIndentation(lines []string, n int, skipFirstLine bool) []string {
|
||||
for i, line := range lines {
|
||||
if i == 0 && skipFirstLine {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(lines[i]) >= n {
|
||||
lines[i] = line[n:]
|
||||
}
|
||||
}
|
||||
return lines
|
||||
}
|
||||
|
||||
// Docf returns unindented and formatted string as here-document.
|
||||
// Formatting is done as for fmt.Printf().
|
||||
func Docf(raw string, args ...interface{}) string {
|
||||
return fmt.Sprintf(Doc(raw), args...)
|
||||
}
|
|
@ -29,8 +29,10 @@ github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/filter
|
|||
github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta
|
||||
github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/mock
|
||||
# github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd
|
||||
## explicit
|
||||
github.com/MakeNowJust/heredoc
|
||||
# github.com/MakeNowJust/heredoc/v2 v2.0.1
|
||||
## explicit
|
||||
github.com/MakeNowJust/heredoc/v2
|
||||
# github.com/Masterminds/goutils v1.1.0
|
||||
github.com/Masterminds/goutils
|
||||
# github.com/Masterminds/semver/v3 v3.1.0
|
||||
|
|
Loading…
Reference in New Issue