util.go
This file
Path
doc/util.go
52 lines · 1.5 KiB · Go
Last changed by
More linting (#2099)Ville Skyttäbefore adoption6b5f577
History of this fileTake it
1// Copyright 2013-2023 The Cobra Authors2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.1415package doc1617import (18 "strings"1920 "github.com/spf13/cobra"21)2223// Test to see if we have a reason to print See Also information in docs24// Basically this is a test for a parent command or a subcommand which is25// both not deprecated and not the autogenerated help command.26func hasSeeAlso(cmd *cobra.Command) bool {27 if cmd.HasParent() {28 return true29 }30 for _, c := range cmd.Commands() {31 if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {32 continue33 }34 return true35 }36 return false37}3839// Temporary workaround for yaml lib generating incorrect yaml with long strings40// that do not contain \n.41func forceMultiLine(s string) string {42 if len(s) > 60 && !strings.Contains(s, "\n") {43 s += "\n"44 }45 return s46}4748type byName []*cobra.Command4950func (s byName) Len() int { return len(s) }51func (s byName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }52func (s byName) Less(i, j int) bool { return s[i].Name() < s[j].Name() }