...

Source file src/github.com/spf13/cobra/doc/util.go

Documentation: github.com/spf13/cobra/doc

     1  // Copyright 2013-2023 The Cobra Authors
     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 at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // 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 and
    13  // limitations under the License.
    14  
    15  package doc
    16  
    17  import (
    18  	"strings"
    19  
    20  	"github.com/spf13/cobra"
    21  )
    22  
    23  // Test to see if we have a reason to print See Also information in docs
    24  // Basically this is a test for a parent command or a subcommand which is
    25  // both not deprecated and not the autogenerated help command.
    26  func hasSeeAlso(cmd *cobra.Command) bool {
    27  	if cmd.HasParent() {
    28  		return true
    29  	}
    30  	for _, c := range cmd.Commands() {
    31  		if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
    32  			continue
    33  		}
    34  		return true
    35  	}
    36  	return false
    37  }
    38  
    39  // Temporary workaround for yaml lib generating incorrect yaml with long strings
    40  // that do not contain \n.
    41  func forceMultiLine(s string) string {
    42  	if len(s) > 60 && !strings.Contains(s, "\n") {
    43  		s = s + "\n"
    44  	}
    45  	return s
    46  }
    47  
    48  type byName []*cobra.Command
    49  
    50  func (s byName) Len() int           { return len(s) }
    51  func (s byName) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
    52  func (s byName) Less(i, j int) bool { return s[i].Name() < s[j].Name() }
    53  

View as plain text