From dadd7525743f21afab955c205f954d02d6e92fe8 Mon Sep 17 00:00:00 2001 From: Ole Markus With Date: Tue, 15 Dec 2020 10:49:39 +0100 Subject: [PATCH] Bump heredoc to v2 --- go.mod | 2 +- go.sum | 2 + pkg/edit/BUILD.bazel | 2 +- pkg/edit/edit_test.go | 2 +- pkg/jsonutils/BUILD.bazel | 2 +- pkg/jsonutils/streamwriter_test.go | 2 +- pkg/k8scodecs/BUILD.bazel | 2 +- pkg/k8scodecs/codecs_test.go | 2 +- pkg/kopscodecs/BUILD.bazel | 2 +- pkg/kopscodecs/codecs_test.go | 2 +- pkg/pretty/BUILD.bazel | 2 +- pkg/pretty/help.go | 2 +- .../MakeNowJust/heredoc/v2/BUILD.bazel | 9 ++ .../github.com/MakeNowJust/heredoc/v2/LICENSE | 21 ++++ .../MakeNowJust/heredoc/v2/README.md | 48 +++++++ .../github.com/MakeNowJust/heredoc/v2/go.mod | 3 + .../MakeNowJust/heredoc/v2/heredoc.go | 118 ++++++++++++++++++ vendor/modules.txt | 4 +- 18 files changed, 215 insertions(+), 12 deletions(-) create mode 100644 vendor/github.com/MakeNowJust/heredoc/v2/BUILD.bazel create mode 100644 vendor/github.com/MakeNowJust/heredoc/v2/LICENSE create mode 100644 vendor/github.com/MakeNowJust/heredoc/v2/README.md create mode 100644 vendor/github.com/MakeNowJust/heredoc/v2/go.mod create mode 100644 vendor/github.com/MakeNowJust/heredoc/v2/heredoc.go diff --git a/go.mod b/go.mod index 6f48492f99..e363437e7f 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index 07903b92d0..3ef489f53a 100644 --- a/go.sum +++ b/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= diff --git a/pkg/edit/BUILD.bazel b/pkg/edit/BUILD.bazel index 7816a162d4..5a30dcc0a2 100644 --- a/pkg/edit/BUILD.bazel +++ b/pkg/edit/BUILD.bazel @@ -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", ], diff --git a/pkg/edit/edit_test.go b/pkg/edit/edit_test.go index d69bfa8abb..e0daeb5348 100644 --- a/pkg/edit/edit_test.go +++ b/pkg/edit/edit_test.go @@ -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" diff --git a/pkg/jsonutils/BUILD.bazel b/pkg/jsonutils/BUILD.bazel index ebcf6bdf23..204d21923e 100644 --- a/pkg/jsonutils/BUILD.bazel +++ b/pkg/jsonutils/BUILD.bazel @@ -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"], ) diff --git a/pkg/jsonutils/streamwriter_test.go b/pkg/jsonutils/streamwriter_test.go index b48604f0c4..8f76443078 100644 --- a/pkg/jsonutils/streamwriter_test.go +++ b/pkg/jsonutils/streamwriter_test.go @@ -23,7 +23,7 @@ import ( "strings" "testing" - "github.com/MakeNowJust/heredoc" + "github.com/MakeNowJust/heredoc/v2" ) func TestWriteToken(t *testing.T) { diff --git a/pkg/k8scodecs/BUILD.bazel b/pkg/k8scodecs/BUILD.bazel index 557c554623..957c528102 100644 --- a/pkg/k8scodecs/BUILD.bazel +++ b/pkg/k8scodecs/BUILD.bazel @@ -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", diff --git a/pkg/k8scodecs/codecs_test.go b/pkg/k8scodecs/codecs_test.go index 1155b56660..ef1cecc85f 100644 --- a/pkg/k8scodecs/codecs_test.go +++ b/pkg/k8scodecs/codecs_test.go @@ -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" diff --git a/pkg/kopscodecs/BUILD.bazel b/pkg/kopscodecs/BUILD.bazel index 5d5684e2ed..f4d7031862 100644 --- a/pkg/kopscodecs/BUILD.bazel +++ b/pkg/kopscodecs/BUILD.bazel @@ -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", ], diff --git a/pkg/kopscodecs/codecs_test.go b/pkg/kopscodecs/codecs_test.go index 874b7ed9f7..f94c99618d 100644 --- a/pkg/kopscodecs/codecs_test.go +++ b/pkg/kopscodecs/codecs_test.go @@ -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" diff --git a/pkg/pretty/BUILD.bazel b/pkg/pretty/BUILD.bazel index 3978d3397b..c0045acaa4 100644 --- a/pkg/pretty/BUILD.bazel +++ b/pkg/pretty/BUILD.bazel @@ -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( diff --git a/pkg/pretty/help.go b/pkg/pretty/help.go index f3d75abe17..1916631fca 100644 --- a/pkg/pretty/help.go +++ b/pkg/pretty/help.go @@ -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. diff --git a/vendor/github.com/MakeNowJust/heredoc/v2/BUILD.bazel b/vendor/github.com/MakeNowJust/heredoc/v2/BUILD.bazel new file mode 100644 index 0000000000..b5bf32f314 --- /dev/null +++ b/vendor/github.com/MakeNowJust/heredoc/v2/BUILD.bazel @@ -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"], +) diff --git a/vendor/github.com/MakeNowJust/heredoc/v2/LICENSE b/vendor/github.com/MakeNowJust/heredoc/v2/LICENSE new file mode 100644 index 0000000000..6d0eb9d5d6 --- /dev/null +++ b/vendor/github.com/MakeNowJust/heredoc/v2/LICENSE @@ -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. diff --git a/vendor/github.com/MakeNowJust/heredoc/v2/README.md b/vendor/github.com/MakeNowJust/heredoc/v2/README.md new file mode 100644 index 0000000000..52c8ac525f --- /dev/null +++ b/vendor/github.com/MakeNowJust/heredoc/v2/README.md @@ -0,0 +1,48 @@ +# heredoc + +[![Version](https://img.shields.io/github/v/release/MakeNowJust/heredoc)](https://github.com/MakeNowJust/heredoc/releases) +[![Build Status](https://circleci.com/gh/MakeNowJust/heredoc.svg?style=svg)](https://circleci.com/gh/MakeNowJust/heredoc) +[![GoDoc](https://godoc.org/github.com/MakeNowJusti/heredoc?status.svg)](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. diff --git a/vendor/github.com/MakeNowJust/heredoc/v2/go.mod b/vendor/github.com/MakeNowJust/heredoc/v2/go.mod new file mode 100644 index 0000000000..1203ec5d3e --- /dev/null +++ b/vendor/github.com/MakeNowJust/heredoc/v2/go.mod @@ -0,0 +1,3 @@ +module github.com/MakeNowJust/heredoc/v2 + +go 1.12 diff --git a/vendor/github.com/MakeNowJust/heredoc/v2/heredoc.go b/vendor/github.com/MakeNowJust/heredoc/v2/heredoc.go new file mode 100644 index 0000000000..cf548508a9 --- /dev/null +++ b/vendor/github.com/MakeNowJust/heredoc/v2/heredoc.go @@ -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...) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 8c155e3d85..f7108c90e1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -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