2022-09-16 14:55:56 +03:00
|
|
|
// Copyright 2013-2022 The Cobra Authors
|
2015-08-19 01:33:41 +03:00
|
|
|
//
|
|
|
|
// 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
|
2022-09-16 14:55:56 +03:00
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2015-08-19 01:33:41 +03:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2015-11-24 02:19:16 +03:00
|
|
|
package doc
|
|
|
|
|
2017-01-31 00:45:31 +03:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
2015-08-19 01:33:41 +03:00
|
|
|
|
2022-04-23 22:38:33 +03:00
|
|
|
// cleanCommandName removes problematic characters from a command's name
|
|
|
|
// This allows generating commands such as 'perform run/first'.
|
|
|
|
func cleanCommandName(name string) string {
|
|
|
|
r := strings.NewReplacer(
|
|
|
|
" ", "_",
|
|
|
|
"/", "_",
|
|
|
|
)
|
|
|
|
return r.Replace(name)
|
|
|
|
}
|
|
|
|
|
2015-08-19 01:33:41 +03:00
|
|
|
// Test to see if we have a reason to print See Also information in docs
|
2020-08-11 07:17:29 +03:00
|
|
|
// Basically this is a test for a parent command or a subcommand which is
|
2015-08-19 01:33:41 +03:00
|
|
|
// both not deprecated and not the autogenerated help command.
|
2015-11-24 02:19:16 +03:00
|
|
|
func hasSeeAlso(cmd *cobra.Command) bool {
|
2015-08-19 01:33:41 +03:00
|
|
|
if cmd.HasParent() {
|
|
|
|
return true
|
|
|
|
}
|
2015-11-24 02:19:16 +03:00
|
|
|
for _, c := range cmd.Commands() {
|
2017-03-09 18:37:15 +03:00
|
|
|
if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
|
2015-08-19 01:33:41 +03:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2015-11-24 02:19:16 +03:00
|
|
|
|
2017-01-31 00:45:31 +03:00
|
|
|
// Temporary workaround for yaml lib generating incorrect yaml with long strings
|
|
|
|
// that do not contain \n.
|
|
|
|
func forceMultiLine(s string) string {
|
|
|
|
if len(s) > 60 && !strings.Contains(s, "\n") {
|
|
|
|
s = s + "\n"
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2015-11-24 02:19:16 +03:00
|
|
|
type byName []*cobra.Command
|
|
|
|
|
|
|
|
func (s byName) Len() int { return len(s) }
|
|
|
|
func (s byName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
|
|
|
func (s byName) Less(i, j int) bool { return s[i].Name() < s[j].Name() }
|