Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
anujc25 committed Feb 4, 2025
1 parent 45f3974 commit 70bfe9c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion command/extend.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func Visit(cmd *cobra.Command, f func(c *cobra.Command) error) error {

type commandKey struct{}

func WithCommand(ctx context.Context, cmd *cobra.Command) context.Context {
func ContextWithCommand(ctx context.Context, cmd *cobra.Command) context.Context {
return context.WithValue(ctx, commandKey{}, cmd)
}

Expand Down
2 changes: 1 addition & 1 deletion command/extend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestVisit(t *testing.T) {
func TestCommandFromContext_WithCommand(t *testing.T) {
cmd := &cobra.Command{}
parentCtx := context.Background()
childCtx := WithCommand(parentCtx, cmd)
childCtx := ContextWithCommand(parentCtx, cmd)

if expected, actual := (*cobra.Command)(nil), CommandFromContext(parentCtx); expected != actual {
t.Errorf("expected command %v, actually %v", expected, actual)
Expand Down
1 change: 1 addition & 0 deletions component/stringutils/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"regexp"

"github.com/fatih/color"

"github.com/vmware-tanzu/tanzu-plugin-runtime/component"
)

Expand Down
30 changes: 15 additions & 15 deletions plugin/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/spf13/cobra"

"github.com/vmware-tanzu/tanzu-plugin-runtime/component"
"github.com/vmware-tanzu/tanzu-plugin-runtime/component/stringutils"
"github.com/vmware-tanzu/tanzu-plugin-runtime/config/types"
)

Expand Down Expand Up @@ -195,7 +195,7 @@ func formatUsageHelpSection(cmd *cobra.Command, target types.Target) string {
var output strings.Builder
ic := GetInvocationContext()

output.WriteString(component.Bold(usageStr) + "\n")
output.WriteString(stringutils.Sboldf(usageStr) + "\n")
base := indentStr + "tanzu"

if cmd.Runnable() {
Expand Down Expand Up @@ -324,39 +324,39 @@ func printHelp(cmd *cobra.Command) string {
output.WriteString(formatUsageHelpSection(cmd, target))

if len(cmd.Aliases) > 0 {
output.WriteString("\n" + component.Bold(aliasesStr) + "\n")
output.WriteString("\n" + stringutils.Sboldf(aliasesStr) + "\n")
output.WriteString(indentStr + aliasesWithMappedName(cmd) + "\n")
}

if cmd.HasExample() {
output.WriteString("\n" + component.Bold(examplesStr) + "\n")
output.WriteString("\n" + stringutils.Sboldf(examplesStr) + "\n")
output.WriteString(alignExampleForUsage(cmd.Example) + "\n")
}

if cmd.HasAvailableSubCommands() {
output.WriteString("\n" + component.Bold(availableCommandsStr) + "\n")
output.WriteString("\n" + stringutils.Sboldf(availableCommandsStr) + "\n")
for _, c := range cmd.Commands() {
if c.IsAvailableCommand() {
output.WriteString(indentStr + component.Rpad(c.Name(), c.NamePadding()) + " " + c.Short + "\n")
output.WriteString(indentStr + stringutils.Rpad(c.Name(), c.NamePadding()) + " " + c.Short + "\n")
}
}
}

if cmd.HasAvailableLocalFlags() {
output.WriteString("\n" + component.Bold(flagsStr) + "\n")
output.WriteString("\n" + stringutils.Sboldf(flagsStr) + "\n")
output.WriteString(strings.TrimRight(cmd.LocalFlags().FlagUsages(), " "))
}

if cmd.HasAvailableInheritedFlags() {
output.WriteString("\n" + component.Bold(globalFlagsStr) + "\n")
output.WriteString("\n" + stringutils.Sboldf(globalFlagsStr) + "\n")
output.WriteString(strings.TrimRight(cmd.InheritedFlags().FlagUsages(), " "))
}

if cmd.HasHelpSubCommands() {
output.WriteString("\n" + component.Bold(additionalHelpTopicsStr) + "\n")
output.WriteString("\n" + stringutils.Sboldf(additionalHelpTopicsStr) + "\n")
for _, c := range cmd.Commands() {
if c.IsAdditionalHelpTopicCommand() {
output.WriteString(indentStr + component.Rpad(c.CommandPath(), c.CommandPathPadding()) + " " + c.Short + "\n")
output.WriteString(indentStr + stringutils.Sboldf(c.CommandPath(), c.CommandPathPadding()) + " " + c.Short + "\n")
}
}
}
Expand All @@ -370,11 +370,11 @@ var TemplateFuncs = template.FuncMap{
"printHelp": printHelp,
// The below are not needed but are kept for backwards-compatibility
// in case it is being used through the API
"rpad": component.Rpad,
"bold": component.Bold,
"underline": component.Underline,
"trimTrailingWhitespaces": component.TrimRightSpace,
"beginsWith": component.BeginsWith,
"rpad": stringutils.Rpad,
"bold": stringutils.Sboldf,
"underline": stringutils.Sunderlinef,
"trimTrailingWhitespaces": stringutils.TrimRightSpace,
"beginsWith": stringutils.BeginsWith,
}

func shouldPrintInvocationWithoutTarget(target types.Target, ic *InvocationContext) bool {
Expand Down

0 comments on commit 70bfe9c

Please sign in to comment.