diff --git a/command/extend_test.go b/command/extend_test.go index 76c47ac1..dc5df027 100644 --- a/command/extend_test.go +++ b/command/extend_test.go @@ -127,7 +127,7 @@ func TestVisit(t *testing.T) { return &cobra.Command{Use: "root"} }, visitor: func(cmd *cobra.Command) error { - return fmt.Errorf(cmd.Name()) + return fmt.Errorf("%s", cmd.Name()) }, err: fmt.Errorf("root"), }, { @@ -139,7 +139,7 @@ func TestVisit(t *testing.T) { }, visitor: func(cmd *cobra.Command) error { if cmd.Name() == "child" { - return fmt.Errorf(cmd.Name()) + return fmt.Errorf("%s", cmd.Name()) } return nil }, @@ -156,29 +156,6 @@ func TestVisit(t *testing.T) { } } -// func TestReadStdin(t *testing.T) { -// // TODO is it possible to test the IsTerminal branch? -// expected := []byte("hello") -// var actual []byte - -// scheme := runtime.NewScheme() -// c := NewDefaultConfig("test", scheme) -// c.Stdin = bytes.NewBuffer(expected) -// runE := ReadStdin(c, &actual, "> ") - -// cmd := &cobra.Command{} -// args := []string{} - -// err := runE(cmd, args) - -// if err != nil { -// t.Errorf("expected no error, actually %v", err) -// } -// if string(expected) != string(actual) { -// t.Errorf("expected input %q, actually %q", expected, actual) -// } -// } - func TestCommandFromContext_WithCommand(t *testing.T) { cmd := &cobra.Command{} parentCtx := context.Background() diff --git a/component/characters/spaces.go b/component/characters/spaces.go index 54cbd79e..4aa4684e 100644 --- a/component/characters/spaces.go +++ b/component/characters/spaces.go @@ -1,11 +1,14 @@ // Copyright 2025 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// Package characters provides common set of characters for spaces and icons +// +//nolint:revive package characters const ( LF = "\n" CR = "\r" EnterKey = "\r" - LF_CR = LF + CR + LFCR = LF + CR ) diff --git a/component/printer/color.go b/component/printer/color.go index e1d6c9ae..32f166b4 100644 --- a/component/printer/color.go +++ b/component/printer/color.go @@ -1,6 +1,7 @@ // Copyright 2025 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// Package printer provides helpers to get different prints with different colors package printer import ( diff --git a/component/internal/tabwriter/tabwriter.go b/component/tabwriter/internal/tabwriter.go similarity index 98% rename from component/internal/tabwriter/tabwriter.go rename to component/tabwriter/internal/tabwriter.go index 0214d709..a6a2b728 100644 --- a/component/internal/tabwriter/tabwriter.go +++ b/component/tabwriter/internal/tabwriter.go @@ -5,7 +5,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Package tabwriter implements a write filter (tabwriter.Writer) that +// Package implements a write filter (tabwriter.Writer) that // translates tabbed columns in input into properly aligned text. // // It is a drop-in replacement for the golang text/tabwriter package (https://golang.org/pkg/text/tabwriter), @@ -18,7 +18,10 @@ // repackaged from https://github.com/liggitt/tabwriter/tree/6880f16551ff10c60d3989df2bbd68a55bb3517f // adds IgnoreAnsiCodes -package tabwriter +// Package internal is repackaged from https://github.com/liggitt/tabwriter/tree/6880f16551ff10c60d3989df2bbd68a55bb3517f and adds IgnoreAnsiCodes +// +//nolint:gocyclo,gocritic,unused,nakedret,stylecheck,whitespace +package internal import ( "io" diff --git a/component/tabwriter/tabwriter.go b/component/tabwriter/tabwriter.go index 7d969233..d2b246d7 100644 --- a/component/tabwriter/tabwriter.go +++ b/component/tabwriter/tabwriter.go @@ -1,30 +1,13 @@ // Copyright 2025 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -/* -Copyright 2017 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// repackaged https://github.com/kubernetes/cli-runtime/blob/v0.28.1/pkg/printers - -package table +// Package tabwriter exposes an tabwriter functionality +package tabwriter import ( "io" - "github.com/vmware-tanzu/tanzu-plugin-runtime/component/internal/tabwriter" + "github.com/vmware-tanzu/tanzu-plugin-runtime/component/tabwriter/internal" ) const ( @@ -32,7 +15,7 @@ const ( tabwriterWidth = 4 tabwriterPadding = 3 tabwriterPadChar = ' ' - tabwriterFlags = tabwriter.RememberWidths | tabwriter.IgnoreAnsiCodes + tabwriterFlags = internal.RememberWidths | internal.IgnoreAnsiCodes ) var ( @@ -40,6 +23,6 @@ var ( ) // GetNewTabWriter returns a tabwriter that translates tabbed columns in input into properly aligned text. -func GetNewTabWriter(output io.Writer) *tabwriter.Writer { - return tabwriter.NewWriter(output, tabwriterMinWidth, tabwriterWidth, tabwriterPadding, tabwriterPadChar, tabwriterPaddingStart, tabwriterFlags) +func GetNewTabWriter(output io.Writer) *internal.Writer { + return internal.NewWriter(output, tabwriterMinWidth, tabwriterWidth, tabwriterPadding, tabwriterPadChar, tabwriterPaddingStart, tabwriterFlags) }