Skip to content
Myr

util.go

This file

Path

doc/util.go

51 lines · 1.5 KiB · Go

Last changed by

Correct a typo in doc/util.go (#1184)Felix Yanbefore adoptiona0b86e5

History of this file

Take it

1// Copyright 2015 Red Hat Inc. All rights reserved.2//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// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314package doc1516import (17	"strings"1819	"github.com/spf13/cobra"20)2122// Test to see if we have a reason to print See Also information in docs23// Basically this is a test for a parent command or a subcommand which is24// both not deprecated and not the autogenerated help command.25func hasSeeAlso(cmd *cobra.Command) bool {26	if cmd.HasParent() {27		return true28	}29	for _, c := range cmd.Commands() {30		if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {31			continue32		}33		return true34	}35	return false36}3738// Temporary workaround for yaml lib generating incorrect yaml with long strings39// that do not contain \n.40func forceMultiLine(s string) string {41	if len(s) > 60 && !strings.Contains(s, "\n") {42		s = s + "\n"43	}44	return s45}4647type byName []*cobra.Command4849func (s byName) Len() int           { return len(s) }50func (s byName) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }51func (s byName) Less(i, j int) bool { return s[i].Name() < s[j].Name() }