forked from TrueCloudLab/rclone
vendor: update all dependencies
* Update all dependencies * Remove all `[[constraint]]` from Gopkg.toml * Add in the minimum number of `[[override]]` to build * Remove go get of github.com/inconshreveable/mousetrap as it is vendored * Update docs with new policy on constraints
This commit is contained in:
parent
21383877df
commit
6427029c4e
4902 changed files with 1443417 additions and 227283 deletions
4
vendor/github.com/spf13/cobra/.circleci/config.yml
generated
vendored
4
vendor/github.com/spf13/cobra/.circleci/config.yml
generated
vendored
|
@ -26,11 +26,11 @@ version: 2
|
|||
jobs:
|
||||
go-current:
|
||||
docker:
|
||||
- image: circleci/golang:1.8.3
|
||||
- image: circleci/golang:1.10.0
|
||||
<<: *base
|
||||
go-previous:
|
||||
docker:
|
||||
- image: circleci/golang:1.7.6
|
||||
- image: circleci/golang:1.9.4
|
||||
<<: *base
|
||||
go-latest:
|
||||
docker:
|
||||
|
|
4
vendor/github.com/spf13/cobra/.travis.yml
generated
vendored
4
vendor/github.com/spf13/cobra/.travis.yml
generated
vendored
|
@ -2,8 +2,8 @@ language: go
|
|||
|
||||
matrix:
|
||||
include:
|
||||
- go: 1.7.6
|
||||
- go: 1.8.3
|
||||
- go: 1.9.4
|
||||
- go: 1.10.0
|
||||
- go: tip
|
||||
allow_failures:
|
||||
- go: tip
|
||||
|
|
105
vendor/github.com/spf13/pflag/bytes.go
generated
vendored
Normal file
105
vendor/github.com/spf13/pflag/bytes.go
generated
vendored
Normal file
|
@ -0,0 +1,105 @@
|
|||
package pflag
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// BytesHex adapts []byte for use as a flag. Value of flag is HEX encoded
|
||||
type bytesHexValue []byte
|
||||
|
||||
func (bytesHex bytesHexValue) String() string {
|
||||
return fmt.Sprintf("%X", []byte(bytesHex))
|
||||
}
|
||||
|
||||
func (bytesHex *bytesHexValue) Set(value string) error {
|
||||
bin, err := hex.DecodeString(strings.TrimSpace(value))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*bytesHex = bin
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (*bytesHexValue) Type() string {
|
||||
return "bytesHex"
|
||||
}
|
||||
|
||||
func newBytesHexValue(val []byte, p *[]byte) *bytesHexValue {
|
||||
*p = val
|
||||
return (*bytesHexValue)(p)
|
||||
}
|
||||
|
||||
func bytesHexConv(sval string) (interface{}, error) {
|
||||
|
||||
bin, err := hex.DecodeString(sval)
|
||||
|
||||
if err == nil {
|
||||
return bin, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("invalid string being converted to Bytes: %s %s", sval, err)
|
||||
}
|
||||
|
||||
// GetBytesHex return the []byte value of a flag with the given name
|
||||
func (f *FlagSet) GetBytesHex(name string) ([]byte, error) {
|
||||
val, err := f.getFlagType(name, "bytesHex", bytesHexConv)
|
||||
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
return val.([]byte), nil
|
||||
}
|
||||
|
||||
// BytesHexVar defines an []byte flag with specified name, default value, and usage string.
|
||||
// The argument p points to an []byte variable in which to store the value of the flag.
|
||||
func (f *FlagSet) BytesHexVar(p *[]byte, name string, value []byte, usage string) {
|
||||
f.VarP(newBytesHexValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) BytesHexVarP(p *[]byte, name, shorthand string, value []byte, usage string) {
|
||||
f.VarP(newBytesHexValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
||||
// BytesHexVar defines an []byte flag with specified name, default value, and usage string.
|
||||
// The argument p points to an []byte variable in which to store the value of the flag.
|
||||
func BytesHexVar(p *[]byte, name string, value []byte, usage string) {
|
||||
CommandLine.VarP(newBytesHexValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func BytesHexVarP(p *[]byte, name, shorthand string, value []byte, usage string) {
|
||||
CommandLine.VarP(newBytesHexValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
||||
// BytesHex defines an []byte flag with specified name, default value, and usage string.
|
||||
// The return value is the address of an []byte variable that stores the value of the flag.
|
||||
func (f *FlagSet) BytesHex(name string, value []byte, usage string) *[]byte {
|
||||
p := new([]byte)
|
||||
f.BytesHexVarP(p, name, "", value, usage)
|
||||
return p
|
||||
}
|
||||
|
||||
// BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) BytesHexP(name, shorthand string, value []byte, usage string) *[]byte {
|
||||
p := new([]byte)
|
||||
f.BytesHexVarP(p, name, shorthand, value, usage)
|
||||
return p
|
||||
}
|
||||
|
||||
// BytesHex defines an []byte flag with specified name, default value, and usage string.
|
||||
// The return value is the address of an []byte variable that stores the value of the flag.
|
||||
func BytesHex(name string, value []byte, usage string) *[]byte {
|
||||
return CommandLine.BytesHexP(name, "", value, usage)
|
||||
}
|
||||
|
||||
// BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash.
|
||||
func BytesHexP(name, shorthand string, value []byte, usage string) *[]byte {
|
||||
return CommandLine.BytesHexP(name, shorthand, value, usage)
|
||||
}
|
72
vendor/github.com/spf13/pflag/bytes_test.go
generated
vendored
Normal file
72
vendor/github.com/spf13/pflag/bytes_test.go
generated
vendored
Normal file
|
@ -0,0 +1,72 @@
|
|||
package pflag
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func setUpBytesHex(bytesHex *[]byte) *FlagSet {
|
||||
f := NewFlagSet("test", ContinueOnError)
|
||||
f.BytesHexVar(bytesHex, "bytes", []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, "Some bytes in HEX")
|
||||
f.BytesHexVarP(bytesHex, "bytes2", "B", []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, "Some bytes in HEX")
|
||||
return f
|
||||
}
|
||||
|
||||
func TestBytesHex(t *testing.T) {
|
||||
testCases := []struct {
|
||||
input string
|
||||
success bool
|
||||
expected string
|
||||
}{
|
||||
/// Positive cases
|
||||
{"", true, ""}, // Is empty string OK ?
|
||||
{"01", true, "01"},
|
||||
{"0101", true, "0101"},
|
||||
{"1234567890abcdef", true, "1234567890ABCDEF"},
|
||||
{"1234567890ABCDEF", true, "1234567890ABCDEF"},
|
||||
|
||||
// Negative cases
|
||||
{"0", false, ""}, // Short string
|
||||
{"000", false, ""}, /// Odd-length string
|
||||
{"qq", false, ""}, /// non-hex character
|
||||
}
|
||||
|
||||
devnull, _ := os.Open(os.DevNull)
|
||||
os.Stderr = devnull
|
||||
|
||||
for i := range testCases {
|
||||
var bytesHex []byte
|
||||
f := setUpBytesHex(&bytesHex)
|
||||
|
||||
tc := &testCases[i]
|
||||
|
||||
// --bytes
|
||||
args := []string{
|
||||
fmt.Sprintf("--bytes=%s", tc.input),
|
||||
fmt.Sprintf("-B %s", tc.input),
|
||||
fmt.Sprintf("--bytes2=%s", tc.input),
|
||||
}
|
||||
|
||||
for _, arg := range args {
|
||||
err := f.Parse([]string{arg})
|
||||
|
||||
if err != nil && tc.success == true {
|
||||
t.Errorf("expected success, got %q", err)
|
||||
continue
|
||||
} else if err == nil && tc.success == false {
|
||||
// bytesHex, err := f.GetBytesHex("bytes")
|
||||
t.Errorf("expected failure while processing %q", tc.input)
|
||||
continue
|
||||
} else if tc.success {
|
||||
bytesHex, err := f.GetBytesHex("bytes")
|
||||
if err != nil {
|
||||
t.Errorf("Got error trying to fetch the IP flag: %v", err)
|
||||
}
|
||||
if fmt.Sprintf("%X", bytesHex) != tc.expected {
|
||||
t.Errorf("expected %q, got '%X'", tc.expected, bytesHex)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
98
vendor/github.com/spf13/pflag/flag.go
generated
vendored
98
vendor/github.com/spf13/pflag/flag.go
generated
vendored
|
@ -101,6 +101,7 @@ package pflag
|
|||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
goflag "flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
@ -123,6 +124,12 @@ const (
|
|||
PanicOnError
|
||||
)
|
||||
|
||||
// ParseErrorsWhitelist defines the parsing errors that can be ignored
|
||||
type ParseErrorsWhitelist struct {
|
||||
// UnknownFlags will ignore unknown flags errors and continue parsing rest of the flags
|
||||
UnknownFlags bool
|
||||
}
|
||||
|
||||
// NormalizedName is a flag name that has been normalized according to rules
|
||||
// for the FlagSet (e.g. making '-' and '_' equivalent).
|
||||
type NormalizedName string
|
||||
|
@ -138,6 +145,9 @@ type FlagSet struct {
|
|||
// help/usage messages.
|
||||
SortFlags bool
|
||||
|
||||
// ParseErrorsWhitelist is used to configure a whitelist of errors
|
||||
ParseErrorsWhitelist ParseErrorsWhitelist
|
||||
|
||||
name string
|
||||
parsed bool
|
||||
actual map[NormalizedName]*Flag
|
||||
|
@ -153,6 +163,8 @@ type FlagSet struct {
|
|||
output io.Writer // nil means stderr; use out() accessor
|
||||
interspersed bool // allow interspersed option/non-option args
|
||||
normalizeNameFunc func(f *FlagSet, name string) NormalizedName
|
||||
|
||||
addedGoFlagSets []*goflag.FlagSet
|
||||
}
|
||||
|
||||
// A Flag represents the state of a flag.
|
||||
|
@ -267,16 +279,16 @@ func (f *FlagSet) VisitAll(fn func(*Flag)) {
|
|||
}
|
||||
}
|
||||
|
||||
// HasFlags returns a bool to indicate if the FlagSet has any flags definied.
|
||||
// HasFlags returns a bool to indicate if the FlagSet has any flags defined.
|
||||
func (f *FlagSet) HasFlags() bool {
|
||||
return len(f.formal) > 0
|
||||
}
|
||||
|
||||
// HasAvailableFlags returns a bool to indicate if the FlagSet has any flags
|
||||
// definied that are not hidden or deprecated.
|
||||
// that are not hidden.
|
||||
func (f *FlagSet) HasAvailableFlags() bool {
|
||||
for _, flag := range f.formal {
|
||||
if !flag.Hidden && len(flag.Deprecated) == 0 {
|
||||
if !flag.Hidden {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -386,6 +398,7 @@ func (f *FlagSet) MarkDeprecated(name string, usageMessage string) error {
|
|||
return fmt.Errorf("deprecated message for flag %q must be set", name)
|
||||
}
|
||||
flag.Deprecated = usageMessage
|
||||
flag.Hidden = true
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -586,11 +599,14 @@ func wrapN(i, slop int, s string) (string, string) {
|
|||
return s, ""
|
||||
}
|
||||
|
||||
w := strings.LastIndexAny(s[:i], " \t")
|
||||
w := strings.LastIndexAny(s[:i], " \t\n")
|
||||
if w <= 0 {
|
||||
return s, ""
|
||||
}
|
||||
|
||||
nlPos := strings.LastIndex(s[:i], "\n")
|
||||
if nlPos > 0 && nlPos < w {
|
||||
return s[:nlPos], s[nlPos+1:]
|
||||
}
|
||||
return s[:w], s[w+1:]
|
||||
}
|
||||
|
||||
|
@ -599,7 +615,7 @@ func wrapN(i, slop int, s string) (string, string) {
|
|||
// caller). Pass `w` == 0 to do no wrapping
|
||||
func wrap(i, w int, s string) string {
|
||||
if w == 0 {
|
||||
return s
|
||||
return strings.Replace(s, "\n", "\n"+strings.Repeat(" ", i), -1)
|
||||
}
|
||||
|
||||
// space between indent i and end of line width w into which
|
||||
|
@ -617,7 +633,7 @@ func wrap(i, w int, s string) string {
|
|||
}
|
||||
// If still not enough space then don't even try to wrap.
|
||||
if wrap < 24 {
|
||||
return s
|
||||
return strings.Replace(s, "\n", r, -1)
|
||||
}
|
||||
|
||||
// Try to avoid short orphan words on the final line, by
|
||||
|
@ -629,14 +645,14 @@ func wrap(i, w int, s string) string {
|
|||
// Handle first line, which is indented by the caller (or the
|
||||
// special case above)
|
||||
l, s = wrapN(wrap, slop, s)
|
||||
r = r + l
|
||||
r = r + strings.Replace(l, "\n", "\n"+strings.Repeat(" ", i), -1)
|
||||
|
||||
// Now wrap the rest
|
||||
for s != "" {
|
||||
var t string
|
||||
|
||||
t, s = wrapN(wrap, slop, s)
|
||||
r = r + "\n" + strings.Repeat(" ", i) + t
|
||||
r = r + "\n" + strings.Repeat(" ", i) + strings.Replace(t, "\n", "\n"+strings.Repeat(" ", i), -1)
|
||||
}
|
||||
|
||||
return r
|
||||
|
@ -653,7 +669,7 @@ func (f *FlagSet) FlagUsagesWrapped(cols int) string {
|
|||
|
||||
maxlen := 0
|
||||
f.VisitAll(func(flag *Flag) {
|
||||
if flag.Deprecated != "" || flag.Hidden {
|
||||
if flag.Hidden {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -700,6 +716,9 @@ func (f *FlagSet) FlagUsagesWrapped(cols int) string {
|
|||
line += fmt.Sprintf(" (default %s)", flag.DefValue)
|
||||
}
|
||||
}
|
||||
if len(flag.Deprecated) != 0 {
|
||||
line += fmt.Sprintf(" (DEPRECATED: %s)", flag.Deprecated)
|
||||
}
|
||||
|
||||
lines = append(lines, line)
|
||||
})
|
||||
|
@ -896,6 +915,25 @@ func (f *FlagSet) usage() {
|
|||
}
|
||||
}
|
||||
|
||||
//--unknown (args will be empty)
|
||||
//--unknown --next-flag ... (args will be --next-flag ...)
|
||||
//--unknown arg ... (args will be arg ...)
|
||||
func stripUnknownFlagValue(args []string) []string {
|
||||
if len(args) == 0 {
|
||||
//--unknown
|
||||
return args
|
||||
}
|
||||
|
||||
first := args[0]
|
||||
if first[0] == '-' {
|
||||
//--unknown --next-flag ...
|
||||
return args
|
||||
}
|
||||
|
||||
//--unknown arg ... (args will be arg ...)
|
||||
return args[1:]
|
||||
}
|
||||
|
||||
func (f *FlagSet) parseLongArg(s string, args []string, fn parseFunc) (a []string, err error) {
|
||||
a = args
|
||||
name := s[2:]
|
||||
|
@ -907,13 +945,24 @@ func (f *FlagSet) parseLongArg(s string, args []string, fn parseFunc) (a []strin
|
|||
split := strings.SplitN(name, "=", 2)
|
||||
name = split[0]
|
||||
flag, exists := f.formal[f.normalizeFlagName(name)]
|
||||
|
||||
if !exists {
|
||||
if name == "help" { // special case for nice help message.
|
||||
switch {
|
||||
case name == "help":
|
||||
f.usage()
|
||||
return a, ErrHelp
|
||||
case f.ParseErrorsWhitelist.UnknownFlags:
|
||||
// --unknown=unknownval arg ...
|
||||
// we do not want to lose arg in this case
|
||||
if len(split) >= 2 {
|
||||
return a, nil
|
||||
}
|
||||
|
||||
return stripUnknownFlagValue(a), nil
|
||||
default:
|
||||
err = f.failf("unknown flag: --%s", name)
|
||||
return
|
||||
}
|
||||
err = f.failf("unknown flag: --%s", name)
|
||||
return
|
||||
}
|
||||
|
||||
var value string
|
||||
|
@ -951,13 +1000,25 @@ func (f *FlagSet) parseSingleShortArg(shorthands string, args []string, fn parse
|
|||
|
||||
flag, exists := f.shorthands[c]
|
||||
if !exists {
|
||||
if c == 'h' { // special case for nice help message.
|
||||
switch {
|
||||
case c == 'h':
|
||||
f.usage()
|
||||
err = ErrHelp
|
||||
return
|
||||
case f.ParseErrorsWhitelist.UnknownFlags:
|
||||
// '-f=arg arg ...'
|
||||
// we do not want to lose arg in this case
|
||||
if len(shorthands) > 2 && shorthands[1] == '=' {
|
||||
outShorts = ""
|
||||
return
|
||||
}
|
||||
|
||||
outArgs = stripUnknownFlagValue(outArgs)
|
||||
return
|
||||
default:
|
||||
err = f.failf("unknown shorthand flag: %q in -%s", c, shorthands)
|
||||
return
|
||||
}
|
||||
err = f.failf("unknown shorthand flag: %q in -%s", c, shorthands)
|
||||
return
|
||||
}
|
||||
|
||||
var value string
|
||||
|
@ -1044,6 +1105,11 @@ func (f *FlagSet) parseArgs(args []string, fn parseFunc) (err error) {
|
|||
// are defined and before flags are accessed by the program.
|
||||
// The return value will be ErrHelp if -help was set but not defined.
|
||||
func (f *FlagSet) Parse(arguments []string) error {
|
||||
if f.addedGoFlagSets != nil {
|
||||
for _, goFlagSet := range f.addedGoFlagSets {
|
||||
goFlagSet.Parse(nil)
|
||||
}
|
||||
}
|
||||
f.parsed = true
|
||||
|
||||
if len(arguments) < 0 {
|
||||
|
|
105
vendor/github.com/spf13/pflag/flag_test.go
generated
vendored
105
vendor/github.com/spf13/pflag/flag_test.go
generated
vendored
|
@ -389,7 +389,78 @@ func testParseAll(f *FlagSet, t *testing.T) {
|
|||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("f.ParseAll() fail to restore the args")
|
||||
t.Errorf("Got: %v", got)
|
||||
t.Errorf("Got: %v", got)
|
||||
t.Errorf("Want: %v", want)
|
||||
}
|
||||
}
|
||||
|
||||
func testParseWithUnknownFlags(f *FlagSet, t *testing.T) {
|
||||
if f.Parsed() {
|
||||
t.Error("f.Parse() = true before Parse")
|
||||
}
|
||||
f.ParseErrorsWhitelist.UnknownFlags = true
|
||||
|
||||
f.BoolP("boola", "a", false, "bool value")
|
||||
f.BoolP("boolb", "b", false, "bool2 value")
|
||||
f.BoolP("boolc", "c", false, "bool3 value")
|
||||
f.BoolP("boold", "d", false, "bool4 value")
|
||||
f.BoolP("boole", "e", false, "bool4 value")
|
||||
f.StringP("stringa", "s", "0", "string value")
|
||||
f.StringP("stringz", "z", "0", "string value")
|
||||
f.StringP("stringx", "x", "0", "string value")
|
||||
f.StringP("stringy", "y", "0", "string value")
|
||||
f.StringP("stringo", "o", "0", "string value")
|
||||
f.Lookup("stringx").NoOptDefVal = "1"
|
||||
args := []string{
|
||||
"-ab",
|
||||
"-cs=xx",
|
||||
"--stringz=something",
|
||||
"--unknown1",
|
||||
"unknown1Value",
|
||||
"-d=true",
|
||||
"-x",
|
||||
"--unknown2=unknown2Value",
|
||||
"-u=unknown3Value",
|
||||
"-p",
|
||||
"unknown4Value",
|
||||
"-q", //another unknown with bool value
|
||||
"-y",
|
||||
"ee",
|
||||
"--unknown7=unknown7value",
|
||||
"--stringo=ovalue",
|
||||
"--unknown8=unknown8value",
|
||||
"--boole",
|
||||
"--unknown6",
|
||||
}
|
||||
want := []string{
|
||||
"boola", "true",
|
||||
"boolb", "true",
|
||||
"boolc", "true",
|
||||
"stringa", "xx",
|
||||
"stringz", "something",
|
||||
"boold", "true",
|
||||
"stringx", "1",
|
||||
"stringy", "ee",
|
||||
"stringo", "ovalue",
|
||||
"boole", "true",
|
||||
}
|
||||
got := []string{}
|
||||
store := func(flag *Flag, value string) error {
|
||||
got = append(got, flag.Name)
|
||||
if len(value) > 0 {
|
||||
got = append(got, value)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if err := f.ParseAll(args, store); err != nil {
|
||||
t.Errorf("expected no error, got %s", err)
|
||||
}
|
||||
if !f.Parsed() {
|
||||
t.Errorf("f.Parse() = false after Parse")
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("f.ParseAll() fail to restore the args")
|
||||
t.Errorf("Got: %v", got)
|
||||
t.Errorf("Want: %v", want)
|
||||
}
|
||||
}
|
||||
|
@ -500,6 +571,11 @@ func TestParseAll(t *testing.T) {
|
|||
testParseAll(GetCommandLine(), t)
|
||||
}
|
||||
|
||||
func TestIgnoreUnknownFlags(t *testing.T) {
|
||||
ResetForTesting(func() { t.Error("bad parse") })
|
||||
testParseWithUnknownFlags(GetCommandLine(), t)
|
||||
}
|
||||
|
||||
func TestFlagSetParse(t *testing.T) {
|
||||
testParse(NewFlagSet("test", ContinueOnError), t)
|
||||
}
|
||||
|
@ -890,10 +966,14 @@ func TestTermination(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDeprecatedFlagInDocs(t *testing.T) {
|
||||
func getDeprecatedFlagSet() *FlagSet {
|
||||
f := NewFlagSet("bob", ContinueOnError)
|
||||
f.Bool("badflag", true, "always true")
|
||||
f.MarkDeprecated("badflag", "use --good-flag instead")
|
||||
return f
|
||||
}
|
||||
func TestDeprecatedFlagInDocs(t *testing.T) {
|
||||
f := getDeprecatedFlagSet()
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
f.SetOutput(out)
|
||||
|
@ -904,6 +984,27 @@ func TestDeprecatedFlagInDocs(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestUnHiddenDeprecatedFlagInDocs(t *testing.T) {
|
||||
f := getDeprecatedFlagSet()
|
||||
flg := f.Lookup("badflag")
|
||||
if flg == nil {
|
||||
t.Fatalf("Unable to lookup 'bob' in TestUnHiddenDeprecatedFlagInDocs")
|
||||
}
|
||||
flg.Hidden = false
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
f.SetOutput(out)
|
||||
f.PrintDefaults()
|
||||
|
||||
defaults := out.String()
|
||||
if !strings.Contains(defaults, "badflag") {
|
||||
t.Errorf("Did not find deprecated flag in usage!")
|
||||
}
|
||||
if !strings.Contains(defaults, "use --good-flag instead") {
|
||||
t.Errorf("Did not find 'use --good-flag instead' in defaults")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeprecatedFlagShorthandInDocs(t *testing.T) {
|
||||
f := NewFlagSet("bob", ContinueOnError)
|
||||
name := "noshorthandflag"
|
||||
|
|
4
vendor/github.com/spf13/pflag/golangflag.go
generated
vendored
4
vendor/github.com/spf13/pflag/golangflag.go
generated
vendored
|
@ -98,4 +98,8 @@ func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet) {
|
|||
newSet.VisitAll(func(goflag *goflag.Flag) {
|
||||
f.AddGoFlag(goflag)
|
||||
})
|
||||
if f.addedGoFlagSets == nil {
|
||||
f.addedGoFlagSets = make([]*goflag.FlagSet, 0)
|
||||
}
|
||||
f.addedGoFlagSets = append(f.addedGoFlagSets, newSet)
|
||||
}
|
||||
|
|
8
vendor/github.com/spf13/pflag/golangflag_test.go
generated
vendored
8
vendor/github.com/spf13/pflag/golangflag_test.go
generated
vendored
|
@ -36,4 +36,12 @@ func TestGoflags(t *testing.T) {
|
|||
if getBool != true {
|
||||
t.Fatalf("expected getBool=true but got getBool=%v", getBool)
|
||||
}
|
||||
if !f.Parsed() {
|
||||
t.Fatal("f.Parsed() return false after f.Parse() called")
|
||||
}
|
||||
|
||||
// in fact it is useless. because `go test` called flag.Parse()
|
||||
if !goflag.CommandLine.Parsed() {
|
||||
t.Fatal("goflag.CommandLine.Parsed() return false after f.Parse() called")
|
||||
}
|
||||
}
|
||||
|
|
74
vendor/github.com/spf13/pflag/printusage_test.go
generated
vendored
Normal file
74
vendor/github.com/spf13/pflag/printusage_test.go
generated
vendored
Normal file
|
@ -0,0 +1,74 @@
|
|||
package pflag
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const expectedOutput = ` --long-form Some description
|
||||
--long-form2 Some description
|
||||
with multiline
|
||||
-s, --long-name Some description
|
||||
-t, --long-name2 Some description with
|
||||
multiline
|
||||
`
|
||||
|
||||
func setUpPFlagSet(buf io.Writer) *FlagSet {
|
||||
f := NewFlagSet("test", ExitOnError)
|
||||
f.Bool("long-form", false, "Some description")
|
||||
f.Bool("long-form2", false, "Some description\n with multiline")
|
||||
f.BoolP("long-name", "s", false, "Some description")
|
||||
f.BoolP("long-name2", "t", false, "Some description with\n multiline")
|
||||
f.SetOutput(buf)
|
||||
return f
|
||||
}
|
||||
|
||||
func TestPrintUsage(t *testing.T) {
|
||||
buf := bytes.Buffer{}
|
||||
f := setUpPFlagSet(&buf)
|
||||
f.PrintDefaults()
|
||||
res := buf.String()
|
||||
if res != expectedOutput {
|
||||
t.Errorf("Expected \n%s \nActual \n%s", expectedOutput, res)
|
||||
}
|
||||
}
|
||||
|
||||
func setUpPFlagSet2(buf io.Writer) *FlagSet {
|
||||
f := NewFlagSet("test", ExitOnError)
|
||||
f.Bool("long-form", false, "Some description")
|
||||
f.Bool("long-form2", false, "Some description\n with multiline")
|
||||
f.BoolP("long-name", "s", false, "Some description")
|
||||
f.BoolP("long-name2", "t", false, "Some description with\n multiline")
|
||||
f.StringP("some-very-long-arg", "l", "test", "Some very long description having break the limit")
|
||||
f.StringP("other-very-long-arg", "o", "long-default-value", "Some very long description having break the limit")
|
||||
f.String("some-very-long-arg2", "very long default value", "Some very long description\nwith line break\nmultiple")
|
||||
f.SetOutput(buf)
|
||||
return f
|
||||
}
|
||||
|
||||
const expectedOutput2 = ` --long-form Some description
|
||||
--long-form2 Some description
|
||||
with multiline
|
||||
-s, --long-name Some description
|
||||
-t, --long-name2 Some description with
|
||||
multiline
|
||||
-o, --other-very-long-arg string Some very long description having
|
||||
break the limit (default
|
||||
"long-default-value")
|
||||
-l, --some-very-long-arg string Some very long description having
|
||||
break the limit (default "test")
|
||||
--some-very-long-arg2 string Some very long description
|
||||
with line break
|
||||
multiple (default "very long default
|
||||
value")
|
||||
`
|
||||
|
||||
func TestPrintUsage_2(t *testing.T) {
|
||||
buf := bytes.Buffer{}
|
||||
f := setUpPFlagSet2(&buf)
|
||||
res := f.FlagUsagesWrapped(80)
|
||||
if res != expectedOutput2 {
|
||||
t.Errorf("Expected \n%q \nActual \n%q", expectedOutput2, res)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue