mirror of
https://github.com/spf13/cobra
synced 2024-11-24 22:57:12 +00:00
b5bc3e3275
* main: (39 commits) Add '--version' flag to Help output (#1707) Expose ValidateRequiredFlags and ValidateFlagGroups (#1760) Document option to hide the default completion cmd (#1779) ci: add workflow_dispatch (#1387) add missing license headers (#1809) ci: use action/setup-go's cache (#1783) Adjustments to documentation (#1656) Rename Powershell completion tests (#1803) Support for case-insensitive command names (#1802) Deprecate ExactValidArgs() and test combinations of args validators (#1643) Use correct stale action `exempt-` yaml keys (#1800) With go 1.18, we must use go install for a binary (#1726) Clarify SetContext documentation (#1748) ci: test on Golang 1.19 (#1782) fix: show flags that shadow parent persistent flag in child help (#1776) Update gopkg.in/yaml.v2 to gopkg.in/yaml.v3 (#1766) fix(bash-v2): activeHelp length check syntax (#1762) fix: correct command path in see_also for YAML doc (#1771) build(deps): bump github.com/inconshreveable/mousetrap (#1774) docs: add zitadel to the list (#1772) ...
62 lines
1.8 KiB
Go
62 lines
1.8 KiB
Go
// Copyright 2013-2022 The Cobra Authors
|
|
//
|
|
// 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
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// 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.
|
|
|
|
package doc
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// 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)
|
|
}
|
|
|
|
// Test to see if we have a reason to print See Also information in docs
|
|
// Basically this is a test for a parent command or a subcommand which is
|
|
// both not deprecated and not the autogenerated help command.
|
|
func hasSeeAlso(cmd *cobra.Command) bool {
|
|
if cmd.HasParent() {
|
|
return true
|
|
}
|
|
for _, c := range cmd.Commands() {
|
|
if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
|
|
continue
|
|
}
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
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() }
|