fix repos

This commit is contained in:
re 2022-12-12 17:00:41 +03:00
parent 923592041e
commit 0bdb9b08f2
25 changed files with 361 additions and 222 deletions

View File

@ -6,9 +6,9 @@ Cobra is used in many Go projects such as [Kubernetes](https://kubernetes.io/),
[Hugo](https://gohugo.io), and [GitHub CLI](https://github.com/cli/cli) to
name a few. [This list](./projects_using_cobra.md) contains a more extensive list of projects using Cobra.
[![](https://img.shields.io/github/workflow/status/spf13/cobra/Test?longCache=tru&label=Test&logo=github%20actions&logoColor=fff)](https://github.com/spf13/cobra/actions?query=workflow%3ATest)
[![Go Reference](https://pkg.go.dev/badge/github.com/spf13/cobra.svg)](https://pkg.go.dev/github.com/spf13/cobra)
[![Go Report Card](https://goreportcard.com/badge/github.com/spf13/cobra)](https://goreportcard.com/report/github.com/spf13/cobra)
[![](https://img.shields.io/github/workflow/status/spf13/cobra/Test?longCache=tru&label=Test&logo=github%20actions&logoColor=fff)](https://git.internal/re/cobra/actions?query=workflow%3ATest)
[![Go Reference](https://pkg.go.dev/badge/git.internal/re/cobra.svg)](https://pkg.go.dev/git.internal/re/cobra)
[![Go Report Card](https://goreportcard.com/badge/git.internal/re/cobra)](https://goreportcard.com/report/git.internal/re/cobra)
[![Slack](https://img.shields.io/badge/Slack-cobra-brightgreen)](https://gophers.slack.com/archives/CD3LP1199)
# Overview
@ -63,7 +63,7 @@ have children commands and optionally run an action.
In the example above, 'server' is the command.
[More about cobra.Command](https://pkg.go.dev/github.com/spf13/cobra#Command)
[More about cobra.Command](https://pkg.go.dev/git.internal/re/cobra#Command)
## Flags
@ -83,13 +83,13 @@ Using Cobra is easy. First, use `go get` to install the latest version
of the library.
```
go get -u github.com/spf13/cobra@latest
go get -u git.internal/re/cobra@latest
```
Next, include Cobra in your application:
```go
import "github.com/spf13/cobra"
import "git.internal/re/cobra"
```
# Usage
@ -100,13 +100,13 @@ develop a Cobra-based application. It is the easiest way to incorporate Cobra in
It can be installed by running:
```
go install github.com/spf13/cobra-cli@latest
go install git.internal/re/cobra-cli@latest
```
For complete details on using the Cobra-CLI generator, please read [The Cobra Generator README](https://github.com/spf13/cobra-cli/blob/main/README.md)
For complete details on using the Cobra-CLI generator, please read [The Cobra Generator README](https://git.internal/re/cobra-cli/blob/main/README.md)
For complete details on using the Cobra library, please read the [The Cobra User Guide](user_guide.md).
# License
Cobra is released under the Apache 2.0 license. See [LICENSE.txt](https://github.com/spf13/cobra/blob/master/LICENSE.txt)
Cobra is released under the Apache 2.0 license. See [LICENSE.txt](https://git.internal/re/cobra/blob/master/LICENSE.txt)

View File

@ -208,7 +208,7 @@ __%[1]s_handle_completion_types() {
# Type: menu-complete/menu-complete-backward and insert-completions
# If the user requested inserting one completion at a time, or all
# completions at once on the command-line we must remove the descriptions.
# https://github.com/spf13/cobra/issues/1508
# https://git.internal/re/cobra/issues/1508
local tab=$'\t' comp
while IFS='' read -r comp; do
[[ -z $comp ]] && continue

View File

@ -446,7 +446,7 @@ func (c *Command) HelpFunc() func(*Command, []string) {
return func(c *Command, a []string) {
c.mergePersistentFlags()
// The help should be sent to stdout
// See https://github.com/spf13/cobra/issues/1002
// See https://git.internal/re/cobra/issues/1002
err := tmpl(c.OutOrStdout(), c.HelpTemplate(), c)
if err != nil {
c.PrintErrln(err)
@ -1528,7 +1528,7 @@ func (c *Command) IsAvailableCommand() bool {
// help topic command; additional help topic command is determined by the
// fact that it is NOT runnable/hidden/deprecated, and has no sub commands that
// are runnable/hidden/deprecated.
// Concrete example: https://github.com/spf13/cobra/issues/393#issuecomment-282741924.
// Concrete example: https://git.internal/re/cobra/issues/393#issuecomment-282741924.
func (c *Command) IsAdditionalHelpTopicCommand() bool {
// if a command is runnable, deprecated, or hidden it is not a 'help' command
if c.Runnable() || len(c.Deprecated) != 0 || c.Hidden {

View File

@ -980,7 +980,7 @@ func TestHelpFlagExecutedOnChild(t *testing.T) {
// TestHelpFlagInHelp checks,
// if '--help' flag is shown in help for child (executing `parent help child`),
// that has no other flags.
// Related to https://github.com/spf13/cobra/issues/302.
// Related to https://git.internal/re/cobra/issues/302.
func TestHelpFlagInHelp(t *testing.T) {
parentCmd := &Command{Use: "parent", Run: func(*Command, []string) {}}
@ -1191,8 +1191,8 @@ func TestShorthandVersionFlagOnlyAddedIfVersionNotDefined(t *testing.T) {
}
func TestUsageIsNotPrintedTwice(t *testing.T) {
var cmd = &Command{Use: "root"}
var sub = &Command{Use: "sub"}
cmd := &Command{Use: "root"}
sub := &Command{Use: "sub"}
cmd.AddCommand(sub)
output, _ := executeCommand(cmd, "")
@ -1381,7 +1381,6 @@ func TestCaseSensitivityBackwardCompatibility(t *testing.T) {
if err == nil {
t.Error("Expected error on calling a command in upper case while command names are case sensitive. Got nil.")
}
}
func TestRemoveCommand(t *testing.T) {
@ -1566,7 +1565,7 @@ func TestPersistentHooks(t *testing.T) {
}{
// TODO: currently PersistentPreRun* defined in parent does not
// run if the matching child subcommand has PersistentPreRun.
// If the behavior changes (https://github.com/spf13/cobra/issues/252)
// If the behavior changes (https://git.internal/re/cobra/issues/252)
// this test must be fixed.
{"parentPersPreArgs", parentPersPreArgs},
{"parentPreArgs", parentPreArgs},
@ -1574,7 +1573,7 @@ func TestPersistentHooks(t *testing.T) {
{"parentPostArgs", parentPostArgs},
// TODO: currently PersistentPostRun* defined in parent does not
// run if the matching child subcommand has PersistentPostRun.
// If the behavior changes (https://github.com/spf13/cobra/issues/252)
// If the behavior changes (https://git.internal/re/cobra/issues/252)
// this test must be fixed.
{"parentPersPostArgs", parentPersPostArgs},
} {
@ -1599,7 +1598,7 @@ func TestPersistentHooks(t *testing.T) {
}
}
// Related to https://github.com/spf13/cobra/issues/521.
// Related to https://git.internal/re/cobra/issues/521.
func TestGlobalNormFuncPropagation(t *testing.T) {
normFunc := func(f *pflag.FlagSet, name string) pflag.NormalizedName {
return pflag.NormalizedName(name)
@ -1619,7 +1618,7 @@ func TestGlobalNormFuncPropagation(t *testing.T) {
}
}
// Related to https://github.com/spf13/cobra/issues/521.
// Related to https://git.internal/re/cobra/issues/521.
func TestNormPassedOnLocal(t *testing.T) {
toUpper := func(f *pflag.FlagSet, name string) pflag.NormalizedName {
return pflag.NormalizedName(strings.ToUpper(name))
@ -1633,7 +1632,7 @@ func TestNormPassedOnLocal(t *testing.T) {
}
}
// Related to https://github.com/spf13/cobra/issues/521.
// Related to https://git.internal/re/cobra/issues/521.
func TestNormPassedOnInherited(t *testing.T) {
toUpper := func(f *pflag.FlagSet, name string) pflag.NormalizedName {
return pflag.NormalizedName(strings.ToUpper(name))
@ -1661,7 +1660,7 @@ func TestNormPassedOnInherited(t *testing.T) {
}
}
// Related to https://github.com/spf13/cobra/issues/521.
// Related to https://git.internal/re/cobra/issues/521.
func TestConsistentNormalizedName(t *testing.T) {
toUpper := func(f *pflag.FlagSet, name string) pflag.NormalizedName {
return pflag.NormalizedName(strings.ToUpper(name))
@ -1730,7 +1729,7 @@ func TestCommandsAreSorted(t *testing.T) {
originalNames := []string{"middle", "zlast", "afirst"}
expectedNames := []string{"afirst", "middle", "zlast"}
var rootCmd = &Command{Use: "root"}
rootCmd := &Command{Use: "root"}
for _, name := range originalNames {
rootCmd.AddCommand(&Command{Use: name})
@ -1751,7 +1750,7 @@ func TestEnableCommandSortingIsDisabled(t *testing.T) {
originalNames := []string{"middle", "zlast", "afirst"}
var rootCmd = &Command{Use: "root"}
rootCmd := &Command{Use: "root"}
for _, name := range originalNames {
rootCmd.AddCommand(&Command{Use: name})
@ -1768,7 +1767,7 @@ func TestEnableCommandSortingIsDisabled(t *testing.T) {
}
func TestUsageWithGroup(t *testing.T) {
var rootCmd = &Command{Use: "root", Short: "test", Run: emptyRun}
rootCmd := &Command{Use: "root", Short: "test", Run: emptyRun}
rootCmd.CompletionOptions.DisableDefaultCmd = true
rootCmd.AddGroup(&Group{ID: "group1", Title: "group1"})
@ -1789,7 +1788,7 @@ func TestUsageWithGroup(t *testing.T) {
}
func TestUsageHelpGroup(t *testing.T) {
var rootCmd = &Command{Use: "root", Short: "test", Run: emptyRun}
rootCmd := &Command{Use: "root", Short: "test", Run: emptyRun}
rootCmd.CompletionOptions.DisableDefaultCmd = true
rootCmd.AddGroup(&Group{ID: "group", Title: "group"})
@ -1807,7 +1806,7 @@ func TestUsageHelpGroup(t *testing.T) {
}
func TestUsageCompletionGroup(t *testing.T) {
var rootCmd = &Command{Use: "root", Short: "test", Run: emptyRun}
rootCmd := &Command{Use: "root", Short: "test", Run: emptyRun}
rootCmd.AddGroup(&Group{ID: "group", Title: "group"})
rootCmd.AddGroup(&Group{ID: "help", Title: "help"})
@ -1827,7 +1826,7 @@ func TestUsageCompletionGroup(t *testing.T) {
}
func TestUngroupedCommand(t *testing.T) {
var rootCmd = &Command{Use: "root", Short: "test", Run: emptyRun}
rootCmd := &Command{Use: "root", Short: "test", Run: emptyRun}
rootCmd.AddGroup(&Group{ID: "group", Title: "group"})
rootCmd.AddGroup(&Group{ID: "help", Title: "help"})
@ -1849,7 +1848,7 @@ func TestUngroupedCommand(t *testing.T) {
}
func TestAddGroup(t *testing.T) {
var rootCmd = &Command{Use: "root", Short: "test", Run: emptyRun}
rootCmd := &Command{Use: "root", Short: "test", Run: emptyRun}
rootCmd.AddGroup(&Group{ID: "group", Title: "Test group"})
rootCmd.AddCommand(&Command{Use: "cmd", GroupID: "group", Run: emptyRun})
@ -1863,7 +1862,7 @@ func TestAddGroup(t *testing.T) {
}
func TestWrongGroupFirstLevel(t *testing.T) {
var rootCmd = &Command{Use: "root", Short: "test", Run: emptyRun}
rootCmd := &Command{Use: "root", Short: "test", Run: emptyRun}
rootCmd.AddGroup(&Group{ID: "group", Title: "Test group"})
// Use the wrong group ID
@ -1881,8 +1880,8 @@ func TestWrongGroupFirstLevel(t *testing.T) {
}
func TestWrongGroupNestedLevel(t *testing.T) {
var rootCmd = &Command{Use: "root", Short: "test", Run: emptyRun}
var childCmd = &Command{Use: "child", Run: emptyRun}
rootCmd := &Command{Use: "root", Short: "test", Run: emptyRun}
childCmd := &Command{Use: "child", Run: emptyRun}
rootCmd.AddCommand(childCmd)
childCmd.AddGroup(&Group{ID: "group", Title: "Test group"})
@ -1901,8 +1900,8 @@ func TestWrongGroupNestedLevel(t *testing.T) {
}
func TestWrongGroupForHelp(t *testing.T) {
var rootCmd = &Command{Use: "root", Short: "test", Run: emptyRun}
var childCmd = &Command{Use: "child", Run: emptyRun}
rootCmd := &Command{Use: "root", Short: "test", Run: emptyRun}
childCmd := &Command{Use: "child", Run: emptyRun}
rootCmd.AddCommand(childCmd)
rootCmd.AddGroup(&Group{ID: "group", Title: "Test group"})
@ -1921,8 +1920,8 @@ func TestWrongGroupForHelp(t *testing.T) {
}
func TestWrongGroupForCompletion(t *testing.T) {
var rootCmd = &Command{Use: "root", Short: "test", Run: emptyRun}
var childCmd = &Command{Use: "child", Run: emptyRun}
rootCmd := &Command{Use: "root", Short: "test", Run: emptyRun}
childCmd := &Command{Use: "child", Run: emptyRun}
rootCmd.AddCommand(childCmd)
rootCmd.AddGroup(&Group{ID: "group", Title: "Test group"})
@ -1992,7 +1991,6 @@ func TestCommandPrintRedirection(t *testing.T) {
errBuff, outBuff := bytes.NewBuffer(nil), bytes.NewBuffer(nil)
root := &Command{
Run: func(cmd *Command, args []string) {
cmd.PrintErr("PrintErr")
cmd.PrintErrln("PrintErr", "line")
cmd.PrintErrf("PrintEr%s", "r")
@ -2080,7 +2078,7 @@ Flags:
// TestSortedFlags checks,
// if cmd.LocalFlags() is unsorted when cmd.Flags().SortFlags set to false.
// Related to https://github.com/spf13/cobra/issues/404.
// Related to https://git.internal/re/cobra/issues/404.
func TestSortedFlags(t *testing.T) {
c := &Command{}
c.Flags().SortFlags = false
@ -2106,7 +2104,7 @@ func TestSortedFlags(t *testing.T) {
// TestMergeCommandLineToFlags checks,
// if pflag.CommandLine is correctly merged to c.Flags() after first call
// of c.mergePersistentFlags.
// Related to https://github.com/spf13/cobra/issues/443.
// Related to https://git.internal/re/cobra/issues/443.
func TestMergeCommandLineToFlags(t *testing.T) {
pflag.Bool("boolflag", false, "")
c := &Command{Use: "c", Run: emptyRun}
@ -2120,7 +2118,7 @@ func TestMergeCommandLineToFlags(t *testing.T) {
// TestUseDeprecatedFlags checks,
// if cobra.Execute() prints a message, if a deprecated flag is used.
// Related to https://github.com/spf13/cobra/issues/463.
// Related to https://git.internal/re/cobra/issues/463.
func TestUseDeprecatedFlags(t *testing.T) {
c := &Command{Use: "c", Run: emptyRun}
c.Flags().BoolP("deprecated", "d", false, "deprecated flag")
@ -2235,7 +2233,7 @@ func TestTraverseWithTwoSubcommands(t *testing.T) {
}
// TestUpdateName checks if c.Name() updates on changed c.Use.
// Related to https://github.com/spf13/cobra/pull/422#discussion_r143918343.
// Related to https://git.internal/re/cobra/pull/422#discussion_r143918343.
func TestUpdateName(t *testing.T) {
c := &Command{Use: "name xyz"}
originalName := c.Name()
@ -2517,8 +2515,10 @@ func TestSetContextPersistentPreRun(t *testing.T) {
}
}
const VersionFlag = "--version"
const HelpFlag = "--help"
const (
VersionFlag = "--version"
HelpFlag = "--help"
)
func TestNoRootRunCommandExecutedWithVersionSet(t *testing.T) {
rootCmd := &Command{Use: "root", Version: "1.0.0", Long: "Long description"}

View File

@ -584,7 +584,7 @@ func checkIfFlagCompletion(finalCmd *Command, args []string, lastArg string) (*p
// Flag is shorthand
// We have to get the last shorthand flag name
// e.g. `-asd` => d to provide the correct completion
// https://github.com/spf13/cobra/issues/1257
// https://git.internal/re/cobra/issues/1257
flagName = lastArg[index-1 : index]
}
lastArg = lastArg[index+1:]
@ -610,7 +610,7 @@ func checkIfFlagCompletion(finalCmd *Command, args []string, lastArg string) (*p
// Flag is shorthand
// We have to get the last shorthand flag name
// e.g. `-asd` => d to provide the correct completion
// https://github.com/spf13/cobra/issues/1257
// https://git.internal/re/cobra/issues/1257
flagName = prevArg[len(prevArg)-1:]
}
// Remove the uncompleted flag or else there could be an error created
@ -798,7 +798,6 @@ to your powershell profile.
return cmd.Root().GenPowerShellCompletion(out)
}
return cmd.Root().GenPowerShellCompletionWithDesc(out)
},
}
if haveNoDescFlag {
@ -838,7 +837,7 @@ func CompDebug(msg string, printToStdErr bool) {
// variable BASH_COMP_DEBUG_FILE to the path of some file to be used.
if path := os.Getenv("BASH_COMP_DEBUG_FILE"); path != "" {
f, err := os.OpenFile(path,
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
if err == nil {
defer f.Close()
WriteStringAndCheck(f, msg)

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,7 @@ import (
"strings"
"testing"
"github.com/spf13/cobra"
"git.internal/re/cobra"
)
func emptyRun(*cobra.Command, []string) {}

View File

@ -25,8 +25,8 @@ import (
"strings"
"time"
"git.internal/re/cobra"
"github.com/cpuguy83/go-md2man/v2/md2man"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

View File

@ -8,8 +8,8 @@ package main
import (
"log"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
"git.internal/re/cobra"
"git.internal/re/cobra/doc"
)
func main() {

View File

@ -24,7 +24,7 @@ import (
"strings"
"testing"
"github.com/spf13/cobra"
"git.internal/re/cobra"
)
func assertNoErr(t *testing.T, e error) {

View File

@ -18,8 +18,8 @@ import (
"bytes"
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
"git.internal/re/cobra"
"git.internal/re/cobra/doc"
)
func ExampleGenManTree() {

View File

@ -24,7 +24,7 @@ import (
"strings"
"time"
"github.com/spf13/cobra"
"git.internal/re/cobra"
)
func printOptions(buf *bytes.Buffer, cmd *cobra.Command, name string) error {

View File

@ -8,8 +8,8 @@ package main
import (
"log"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
"git.internal/re/cobra"
"git.internal/re/cobra/doc"
)
func main() {
@ -41,7 +41,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl/cmd"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"github.com/spf13/cobra/doc"
"git.internal/re/cobra/doc"
)
func main() {

View File

@ -21,7 +21,7 @@ import (
"path/filepath"
"testing"
"github.com/spf13/cobra"
"git.internal/re/cobra"
)
func TestGenMdDoc(t *testing.T) {

View File

@ -24,7 +24,7 @@ import (
"strings"
"time"
"github.com/spf13/cobra"
"git.internal/re/cobra"
)
func printOptionsReST(buf *bytes.Buffer, cmd *cobra.Command, name string) error {

View File

@ -8,8 +8,8 @@ package main
import (
"log"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
"git.internal/re/cobra"
"git.internal/re/cobra/doc"
)
func main() {
@ -41,7 +41,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl/cmd"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"github.com/spf13/cobra/doc"
"git.internal/re/cobra/doc"
)
func main() {

View File

@ -21,7 +21,7 @@ import (
"path/filepath"
"testing"
"github.com/spf13/cobra"
"git.internal/re/cobra"
)
func TestGenRSTDoc(t *testing.T) {

View File

@ -17,7 +17,7 @@ package doc
import (
"strings"
"github.com/spf13/cobra"
"git.internal/re/cobra"
)
// Test to see if we have a reason to print See Also information in docs

View File

@ -22,7 +22,7 @@ import (
"sort"
"strings"
"github.com/spf13/cobra"
"git.internal/re/cobra"
"github.com/spf13/pflag"
"gopkg.in/yaml.v3"
)

View File

@ -8,8 +8,8 @@ package main
import (
"log"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
"git.internal/re/cobra"
"git.internal/re/cobra/doc"
)
func main() {
@ -41,7 +41,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl/cmd"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"github.com/spf13/cobra/doc"
"git.internal/re/cobra/doc"
)
func main() {

View File

@ -22,7 +22,7 @@ import (
"path/filepath"
"testing"
"github.com/spf13/cobra"
"git.internal/re/cobra"
)
func TestGenYamlDoc(t *testing.T) {

View File

@ -60,7 +60,7 @@ function __%[1]s_perform_completion
# Some programs may output extra empty lines after the directive.
# Let's ignore them or else it will break completion.
# Ref: https://github.com/spf13/cobra/issues/1279
# Ref: https://git.internal/re/cobra/issues/1279
for line in $results[-1..1]
if test (string trim -- $line) = ""
# Found an empty line, remove it

2
go.mod
View File

@ -1,4 +1,4 @@
module github.com/spf13/cobra
module git.internal/re/cobra
go 1.15

View File

@ -17,7 +17,7 @@ provide your own, which will take precedence over the default one. (This also pr
backwards-compatibility with programs that already have their own `completion` command.)
If you are using the `cobra-cli` generator,
which can be found at [spf13/cobra-cli](https://github.com/spf13/cobra-cli),
which can be found at [spf13/cobra-cli](https://git.internal/re/cobra-cli),
you can create a completion command by running
```bash

View File

@ -32,7 +32,7 @@ func main() {
Cobra-CLI is its own program that will create your application and add any
commands you want. It's the easiest way to incorporate Cobra into your application.
For complete details on using the Cobra generator, please refer to [The Cobra-CLI Generator README](https://github.com/spf13/cobra-cli/blob/main/README.md)
For complete details on using the Cobra generator, please refer to [The Cobra-CLI Generator README](https://git.internal/re/cobra-cli/blob/main/README.md)
## Using the Cobra Library
@ -76,7 +76,7 @@ import (
"fmt"
"os"
"github.com/spf13/cobra"
"git.internal/re/cobra"
"github.com/spf13/viper"
)
@ -171,7 +171,7 @@ package cmd
import (
"fmt"
"github.com/spf13/cobra"
"git.internal/re/cobra"
)
func init() {
@ -198,7 +198,7 @@ package cmd
import (
"fmt"
"github.com/spf13/cobra"
"git.internal/re/cobra"
)
func init() {
@ -397,7 +397,7 @@ import (
"fmt"
"strings"
"github.com/spf13/cobra"
"git.internal/re/cobra"
)
func main() {
@ -574,7 +574,7 @@ package main
import (
"fmt"
"github.com/spf13/cobra"
"git.internal/re/cobra"
)
func main() {