Upgrading server dependancies (#8308)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
b112747de7
Коммит
6d8f122a51
2
vendor/github.com/spf13/afero/.travis.yml
сгенерированный
поставляемый
2
vendor/github.com/spf13/afero/.travis.yml
сгенерированный
поставляемый
@@ -2,8 +2,8 @@ sudo: false
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.7.5
|
||||
- 1.8
|
||||
- 1.9
|
||||
- tip
|
||||
|
||||
os:
|
||||
|
||||
25
vendor/github.com/spf13/cast/cast_test.go
сгенерированный
поставляемый
25
vendor/github.com/spf13/cast/cast_test.go
сгенерированный
поставляемый
@@ -697,6 +697,10 @@ func TestStringMapStringSliceE(t *testing.T) {
|
||||
var stringMapInterface1 = map[string]interface{}{"key 1": []string{"value 1"}, "key 2": []string{"value 2"}}
|
||||
var stringMapInterfaceResult1 = map[string][]string{"key 1": {"value 1"}, "key 2": {"value 2"}}
|
||||
|
||||
var jsonStringMapString = `{"key 1": "value 1", "key 2": "value 2"}`
|
||||
var jsonStringMapStringArray = `{"key 1": ["value 1"], "key 2": ["value 2", "value 3"]}`
|
||||
var jsonStringMapStringArrayResult = map[string][]string{"key 1": {"value 1"}, "key 2": {"value 2", "value 3"}}
|
||||
|
||||
type Key struct {
|
||||
k string
|
||||
}
|
||||
@@ -718,11 +722,15 @@ func TestStringMapStringSliceE(t *testing.T) {
|
||||
{interfaceMapInterfaceSlice, stringMapStringSlice, false},
|
||||
{interfaceMapString, stringMapStringSingleSliceFieldsResult, false},
|
||||
{interfaceMapInterface, stringMapStringSingleSliceFieldsResult, false},
|
||||
{jsonStringMapStringArray, jsonStringMapStringArrayResult, false},
|
||||
|
||||
// errors
|
||||
{nil, nil, true},
|
||||
{testing.T{}, nil, true},
|
||||
{map[interface{}]interface{}{"foo": testing.T{}}, nil, true},
|
||||
{map[interface{}]interface{}{Key{"foo"}: "bar"}, nil, true}, // ToStringE(Key{"foo"}) should fail
|
||||
{jsonStringMapString, nil, true},
|
||||
{"", nil, true},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
@@ -751,9 +759,13 @@ func TestToStringMapE(t *testing.T) {
|
||||
}{
|
||||
{map[interface{}]interface{}{"tag": "tags", "group": "groups"}, map[string]interface{}{"tag": "tags", "group": "groups"}, false},
|
||||
{map[string]interface{}{"tag": "tags", "group": "groups"}, map[string]interface{}{"tag": "tags", "group": "groups"}, false},
|
||||
{`{"tag": "tags", "group": "groups"}`, map[string]interface{}{"tag": "tags", "group": "groups"}, false},
|
||||
{`{"tag": "tags", "group": true}`, map[string]interface{}{"tag": "tags", "group": true}, false},
|
||||
|
||||
// errors
|
||||
{nil, nil, true},
|
||||
{testing.T{}, nil, true},
|
||||
{"", nil, true},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
@@ -783,9 +795,12 @@ func TestToStringMapBoolE(t *testing.T) {
|
||||
{map[interface{}]interface{}{"v1": true, "v2": false}, map[string]bool{"v1": true, "v2": false}, false},
|
||||
{map[string]interface{}{"v1": true, "v2": false}, map[string]bool{"v1": true, "v2": false}, false},
|
||||
{map[string]bool{"v1": true, "v2": false}, map[string]bool{"v1": true, "v2": false}, false},
|
||||
{`{"v1": true, "v2": false}`, map[string]bool{"v1": true, "v2": false}, false},
|
||||
|
||||
// errors
|
||||
{nil, nil, true},
|
||||
{testing.T{}, nil, true},
|
||||
{"", nil, true},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
@@ -811,6 +826,9 @@ func TestToStringMapStringE(t *testing.T) {
|
||||
var stringMapInterface = map[string]interface{}{"key 1": "value 1", "key 2": "value 2", "key 3": "value 3"}
|
||||
var interfaceMapString = map[interface{}]string{"key 1": "value 1", "key 2": "value 2", "key 3": "value 3"}
|
||||
var interfaceMapInterface = map[interface{}]interface{}{"key 1": "value 1", "key 2": "value 2", "key 3": "value 3"}
|
||||
var jsonString = `{"key 1": "value 1", "key 2": "value 2", "key 3": "value 3"}`
|
||||
var invalidJsonString = `{"key 1": "value 1", "key 2": "value 2", "key 3": "value 3"`
|
||||
var emptyString = ""
|
||||
|
||||
tests := []struct {
|
||||
input interface{}
|
||||
@@ -821,9 +839,13 @@ func TestToStringMapStringE(t *testing.T) {
|
||||
{stringMapInterface, stringMapString, false},
|
||||
{interfaceMapString, stringMapString, false},
|
||||
{interfaceMapInterface, stringMapString, false},
|
||||
{jsonString, stringMapString, false},
|
||||
|
||||
// errors
|
||||
{nil, nil, true},
|
||||
{testing.T{}, nil, true},
|
||||
{invalidJsonString, nil, true},
|
||||
{emptyString, nil, true},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
@@ -984,9 +1006,12 @@ func TestToDurationSliceE(t *testing.T) {
|
||||
{[]string{"1s", "1m"}, []time.Duration{time.Second, time.Minute}, false},
|
||||
{[]int{1, 2}, []time.Duration{1, 2}, false},
|
||||
{[]interface{}{1, 3}, []time.Duration{1, 3}, false},
|
||||
{[]time.Duration{1, 3}, []time.Duration{1, 3}, false},
|
||||
|
||||
// errors
|
||||
{nil, nil, true},
|
||||
{testing.T{}, nil, true},
|
||||
{[]string{"invalid"}, nil, true},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
|
||||
20
vendor/github.com/spf13/cast/caste.go
сгенерированный
поставляемый
20
vendor/github.com/spf13/cast/caste.go
сгенерированный
поставляемый
@@ -6,6 +6,7 @@
|
||||
package cast
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
@@ -872,6 +873,9 @@ func ToStringMapStringE(i interface{}) (map[string]string, error) {
|
||||
m[ToString(k)] = ToString(val)
|
||||
}
|
||||
return m, nil
|
||||
case string:
|
||||
err := jsonStringToObject(v, &m)
|
||||
return m, err
|
||||
default:
|
||||
return m, fmt.Errorf("unable to cast %#v of type %T to map[string]string", i, i)
|
||||
}
|
||||
@@ -932,6 +936,9 @@ func ToStringMapStringSliceE(i interface{}) (map[string][]string, error) {
|
||||
}
|
||||
m[key] = value
|
||||
}
|
||||
case string:
|
||||
err := jsonStringToObject(v, &m)
|
||||
return m, err
|
||||
default:
|
||||
return m, fmt.Errorf("unable to cast %#v of type %T to map[string][]string", i, i)
|
||||
}
|
||||
@@ -955,6 +962,9 @@ func ToStringMapBoolE(i interface{}) (map[string]bool, error) {
|
||||
return m, nil
|
||||
case map[string]bool:
|
||||
return v, nil
|
||||
case string:
|
||||
err := jsonStringToObject(v, &m)
|
||||
return m, err
|
||||
default:
|
||||
return m, fmt.Errorf("unable to cast %#v of type %T to map[string]bool", i, i)
|
||||
}
|
||||
@@ -972,6 +982,9 @@ func ToStringMapE(i interface{}) (map[string]interface{}, error) {
|
||||
return m, nil
|
||||
case map[string]interface{}:
|
||||
return v, nil
|
||||
case string:
|
||||
err := jsonStringToObject(v, &m)
|
||||
return m, err
|
||||
default:
|
||||
return m, fmt.Errorf("unable to cast %#v of type %T to map[string]interface{}", i, i)
|
||||
}
|
||||
@@ -1144,3 +1157,10 @@ func parseDateWith(s string, dates []string) (d time.Time, e error) {
|
||||
}
|
||||
return d, fmt.Errorf("unable to parse date: %s", s)
|
||||
}
|
||||
|
||||
// jsonStringToObject attempts to unmarshall a string as JSON into
|
||||
// the object passed as pointer.
|
||||
func jsonStringToObject(s string, v interface{}) error {
|
||||
data := []byte(s)
|
||||
return json.Unmarshal(data, v)
|
||||
}
|
||||
|
||||
38
vendor/github.com/spf13/cobra/.circleci/config.yml
сгенерированный
поставляемый
Обычный файл
38
vendor/github.com/spf13/cobra/.circleci/config.yml
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,38 @@
|
||||
workflows:
|
||||
version: 2
|
||||
main:
|
||||
jobs:
|
||||
- go-current
|
||||
- go-previous
|
||||
- go-latest
|
||||
base: &base
|
||||
working_directory: /go/src/github.com/spf13/cobra
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: "All Commands"
|
||||
command: |
|
||||
mkdir -p bin
|
||||
curl -Lso bin/shellcheck https://github.com/caarlos0/shellcheck-docker/releases/download/v0.4.3/shellcheck
|
||||
chmod +x bin/shellcheck
|
||||
go get -t -v ./...
|
||||
PATH=$PATH:$PWD/bin go test -v ./...
|
||||
go build
|
||||
diff -u <(echo -n) <(gofmt -d -s .)
|
||||
if [ -z $NOVET ]; then
|
||||
diff -u <(echo -n) <(go tool vet . 2>&1 | grep -vE 'ExampleCommand|bash_completions.*Fprint');
|
||||
fi
|
||||
version: 2
|
||||
jobs:
|
||||
go-current:
|
||||
docker:
|
||||
- image: circleci/golang:1.8.3
|
||||
<<: *base
|
||||
go-previous:
|
||||
docker:
|
||||
- image: circleci/golang:1.7.6
|
||||
<<: *base
|
||||
go-latest:
|
||||
docker:
|
||||
- image: circleci/golang:latest
|
||||
<<: *base
|
||||
20
vendor/github.com/spf13/cobra/README.md
сгенерированный
поставляемый
20
vendor/github.com/spf13/cobra/README.md
сгенерированный
поставляемый
@@ -192,6 +192,13 @@ var rootCmd = &cobra.Command{
|
||||
// Do Stuff Here
|
||||
},
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You will additionally define flags and handle configuration in your init() function.
|
||||
@@ -337,8 +344,8 @@ rootCmd.Flags().StringVarP(&Source, "source", "s", "", "Source directory to read
|
||||
|
||||
### Local Flag on Parent Commands
|
||||
|
||||
By default Cobra only parses local flags on the target command, any local flags on
|
||||
parent commands are ignored. By enabling `Command.TraverseChildren` Cobra will
|
||||
By default Cobra only parses local flags on the target command, any local flags on
|
||||
parent commands are ignored. By enabling `Command.TraverseChildren` Cobra will
|
||||
parse local flags on each command before executing the target command.
|
||||
|
||||
```go
|
||||
@@ -366,6 +373,15 @@ when the `--author` flag is not provided by user.
|
||||
|
||||
More in [viper documentation](https://github.com/spf13/viper#working-with-flags).
|
||||
|
||||
### Required flags
|
||||
|
||||
Flags are optional by default. If instead you wish your command to report an error
|
||||
when a flag has not been set, mark it as required:
|
||||
```go
|
||||
rootCmd.Flags().StringVarP(&Region, "region", "r", "", "AWS region (required)")
|
||||
rootCmd.MarkFlagRequired("region")
|
||||
```
|
||||
|
||||
## Positional and Custom Arguments
|
||||
|
||||
Validation of positional arguments can be specified using the `Args` field
|
||||
|
||||
122
vendor/github.com/spf13/cobra/bash_completions.go
сгенерированный
поставляемый
122
vendor/github.com/spf13/cobra/bash_completions.go
сгенерированный
поставляемый
@@ -21,8 +21,8 @@ const (
|
||||
|
||||
func writePreamble(buf *bytes.Buffer, name string) {
|
||||
buf.WriteString(fmt.Sprintf("# bash completion for %-36s -*- shell-script -*-\n", name))
|
||||
buf.WriteString(`
|
||||
__debug()
|
||||
buf.WriteString(fmt.Sprintf(`
|
||||
__%[1]s_debug()
|
||||
{
|
||||
if [[ -n ${BASH_COMP_DEBUG_FILE} ]]; then
|
||||
echo "$*" >> "${BASH_COMP_DEBUG_FILE}"
|
||||
@@ -31,13 +31,13 @@ __debug()
|
||||
|
||||
# Homebrew on Macs have version 1.3 of bash-completion which doesn't include
|
||||
# _init_completion. This is a very minimal version of that function.
|
||||
__my_init_completion()
|
||||
__%[1]s_init_completion()
|
||||
{
|
||||
COMPREPLY=()
|
||||
_get_comp_words_by_ref "$@" cur prev words cword
|
||||
}
|
||||
|
||||
__index_of_word()
|
||||
__%[1]s_index_of_word()
|
||||
{
|
||||
local w word=$1
|
||||
shift
|
||||
@@ -49,7 +49,7 @@ __index_of_word()
|
||||
index=-1
|
||||
}
|
||||
|
||||
__contains_word()
|
||||
__%[1]s_contains_word()
|
||||
{
|
||||
local w word=$1; shift
|
||||
for w in "$@"; do
|
||||
@@ -58,9 +58,9 @@ __contains_word()
|
||||
return 1
|
||||
}
|
||||
|
||||
__handle_reply()
|
||||
__%[1]s_handle_reply()
|
||||
{
|
||||
__debug "${FUNCNAME[0]}"
|
||||
__%[1]s_debug "${FUNCNAME[0]}"
|
||||
case $cur in
|
||||
-*)
|
||||
if [[ $(type -t compopt) = "builtin" ]]; then
|
||||
@@ -85,7 +85,7 @@ __handle_reply()
|
||||
|
||||
local index flag
|
||||
flag="${cur%%=*}"
|
||||
__index_of_word "${flag}" "${flags_with_completion[@]}"
|
||||
__%[1]s_index_of_word "${flag}" "${flags_with_completion[@]}"
|
||||
COMPREPLY=()
|
||||
if [[ ${index} -ge 0 ]]; then
|
||||
PREFIX=""
|
||||
@@ -103,7 +103,7 @@ __handle_reply()
|
||||
|
||||
# check if we are handling a flag with special work handling
|
||||
local index
|
||||
__index_of_word "${prev}" "${flags_with_completion[@]}"
|
||||
__%[1]s_index_of_word "${prev}" "${flags_with_completion[@]}"
|
||||
if [[ ${index} -ge 0 ]]; then
|
||||
${flags_completion[${index}]}
|
||||
return
|
||||
@@ -139,21 +139,21 @@ __handle_reply()
|
||||
}
|
||||
|
||||
# The arguments should be in the form "ext1|ext2|extn"
|
||||
__handle_filename_extension_flag()
|
||||
__%[1]s_handle_filename_extension_flag()
|
||||
{
|
||||
local ext="$1"
|
||||
_filedir "@(${ext})"
|
||||
}
|
||||
|
||||
__handle_subdirs_in_dir_flag()
|
||||
__%[1]s_handle_subdirs_in_dir_flag()
|
||||
{
|
||||
local dir="$1"
|
||||
pushd "${dir}" >/dev/null 2>&1 && _filedir -d && popd >/dev/null 2>&1
|
||||
}
|
||||
|
||||
__handle_flag()
|
||||
__%[1]s_handle_flag()
|
||||
{
|
||||
__debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
|
||||
__%[1]s_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
|
||||
|
||||
# if a command required a flag, and we found it, unset must_have_one_flag()
|
||||
local flagname=${words[c]}
|
||||
@@ -164,27 +164,30 @@ __handle_flag()
|
||||
flagname=${flagname%%=*} # strip everything after the =
|
||||
flagname="${flagname}=" # but put the = back
|
||||
fi
|
||||
__debug "${FUNCNAME[0]}: looking for ${flagname}"
|
||||
if __contains_word "${flagname}" "${must_have_one_flag[@]}"; then
|
||||
__%[1]s_debug "${FUNCNAME[0]}: looking for ${flagname}"
|
||||
if __%[1]s_contains_word "${flagname}" "${must_have_one_flag[@]}"; then
|
||||
must_have_one_flag=()
|
||||
fi
|
||||
|
||||
# if you set a flag which only applies to this command, don't show subcommands
|
||||
if __contains_word "${flagname}" "${local_nonpersistent_flags[@]}"; then
|
||||
if __%[1]s_contains_word "${flagname}" "${local_nonpersistent_flags[@]}"; then
|
||||
commands=()
|
||||
fi
|
||||
|
||||
# keep flag value with flagname as flaghash
|
||||
if [ -n "${flagvalue}" ] ; then
|
||||
flaghash[${flagname}]=${flagvalue}
|
||||
elif [ -n "${words[ $((c+1)) ]}" ] ; then
|
||||
flaghash[${flagname}]=${words[ $((c+1)) ]}
|
||||
else
|
||||
flaghash[${flagname}]="true" # pad "true" for bool flag
|
||||
# flaghash variable is an associative array which is only supported in bash > 3.
|
||||
if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
|
||||
if [ -n "${flagvalue}" ] ; then
|
||||
flaghash[${flagname}]=${flagvalue}
|
||||
elif [ -n "${words[ $((c+1)) ]}" ] ; then
|
||||
flaghash[${flagname}]=${words[ $((c+1)) ]}
|
||||
else
|
||||
flaghash[${flagname}]="true" # pad "true" for bool flag
|
||||
fi
|
||||
fi
|
||||
|
||||
# skip the argument to a two word flag
|
||||
if __contains_word "${words[c]}" "${two_word_flags[@]}"; then
|
||||
if __%[1]s_contains_word "${words[c]}" "${two_word_flags[@]}"; then
|
||||
c=$((c+1))
|
||||
# if we are looking for a flags value, don't show commands
|
||||
if [[ $c -eq $cword ]]; then
|
||||
@@ -196,13 +199,13 @@ __handle_flag()
|
||||
|
||||
}
|
||||
|
||||
__handle_noun()
|
||||
__%[1]s_handle_noun()
|
||||
{
|
||||
__debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
|
||||
__%[1]s_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
|
||||
|
||||
if __contains_word "${words[c]}" "${must_have_one_noun[@]}"; then
|
||||
if __%[1]s_contains_word "${words[c]}" "${must_have_one_noun[@]}"; then
|
||||
must_have_one_noun=()
|
||||
elif __contains_word "${words[c]}" "${noun_aliases[@]}"; then
|
||||
elif __%[1]s_contains_word "${words[c]}" "${noun_aliases[@]}"; then
|
||||
must_have_one_noun=()
|
||||
fi
|
||||
|
||||
@@ -210,9 +213,9 @@ __handle_noun()
|
||||
c=$((c+1))
|
||||
}
|
||||
|
||||
__handle_command()
|
||||
__%[1]s_handle_command()
|
||||
{
|
||||
__debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
|
||||
__%[1]s_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
|
||||
|
||||
local next_command
|
||||
if [[ -n ${last_command} ]]; then
|
||||
@@ -225,30 +228,30 @@ __handle_command()
|
||||
fi
|
||||
fi
|
||||
c=$((c+1))
|
||||
__debug "${FUNCNAME[0]}: looking for ${next_command}"
|
||||
__%[1]s_debug "${FUNCNAME[0]}: looking for ${next_command}"
|
||||
declare -F "$next_command" >/dev/null && $next_command
|
||||
}
|
||||
|
||||
__handle_word()
|
||||
__%[1]s_handle_word()
|
||||
{
|
||||
if [[ $c -ge $cword ]]; then
|
||||
__handle_reply
|
||||
__%[1]s_handle_reply
|
||||
return
|
||||
fi
|
||||
__debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
|
||||
__%[1]s_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
|
||||
if [[ "${words[c]}" == -* ]]; then
|
||||
__handle_flag
|
||||
elif __contains_word "${words[c]}" "${commands[@]}"; then
|
||||
__handle_command
|
||||
elif [[ $c -eq 0 ]] && __contains_word "$(basename "${words[c]}")" "${commands[@]}"; then
|
||||
__handle_command
|
||||
__%[1]s_handle_flag
|
||||
elif __%[1]s_contains_word "${words[c]}" "${commands[@]}"; then
|
||||
__%[1]s_handle_command
|
||||
elif [[ $c -eq 0 ]] && __%[1]s_contains_word "$(basename "${words[c]}")" "${commands[@]}"; then
|
||||
__%[1]s_handle_command
|
||||
else
|
||||
__handle_noun
|
||||
__%[1]s_handle_noun
|
||||
fi
|
||||
__handle_word
|
||||
__%[1]s_handle_word
|
||||
}
|
||||
|
||||
`)
|
||||
`, name))
|
||||
}
|
||||
|
||||
func writePostscript(buf *bytes.Buffer, name string) {
|
||||
@@ -260,7 +263,7 @@ func writePostscript(buf *bytes.Buffer, name string) {
|
||||
if declare -F _init_completion >/dev/null 2>&1; then
|
||||
_init_completion -s || return
|
||||
else
|
||||
__my_init_completion -n "=" || return
|
||||
__%[1]s_init_completion -n "=" || return
|
||||
fi
|
||||
|
||||
local c=0
|
||||
@@ -269,13 +272,13 @@ func writePostscript(buf *bytes.Buffer, name string) {
|
||||
local local_nonpersistent_flags=()
|
||||
local flags_with_completion=()
|
||||
local flags_completion=()
|
||||
local commands=("%s")
|
||||
local commands=("%[1]s")
|
||||
local must_have_one_flag=()
|
||||
local must_have_one_noun=()
|
||||
local last_command
|
||||
local nouns=()
|
||||
|
||||
__handle_word
|
||||
__%[1]s_handle_word
|
||||
}
|
||||
|
||||
`, name))
|
||||
@@ -300,7 +303,7 @@ func writeCommands(buf *bytes.Buffer, cmd *Command) {
|
||||
buf.WriteString("\n")
|
||||
}
|
||||
|
||||
func writeFlagHandler(buf *bytes.Buffer, name string, annotations map[string][]string) {
|
||||
func writeFlagHandler(buf *bytes.Buffer, name string, annotations map[string][]string, cmd *Command) {
|
||||
for key, value := range annotations {
|
||||
switch key {
|
||||
case BashCompFilenameExt:
|
||||
@@ -308,7 +311,7 @@ func writeFlagHandler(buf *bytes.Buffer, name string, annotations map[string][]s
|
||||
|
||||
var ext string
|
||||
if len(value) > 0 {
|
||||
ext = "__handle_filename_extension_flag " + strings.Join(value, "|")
|
||||
ext = fmt.Sprintf("__%s_handle_filename_extension_flag ", cmd.Name()) + strings.Join(value, "|")
|
||||
} else {
|
||||
ext = "_filedir"
|
||||
}
|
||||
@@ -326,7 +329,7 @@ func writeFlagHandler(buf *bytes.Buffer, name string, annotations map[string][]s
|
||||
|
||||
var ext string
|
||||
if len(value) == 1 {
|
||||
ext = "__handle_subdirs_in_dir_flag " + value[0]
|
||||
ext = fmt.Sprintf("__%s_handle_subdirs_in_dir_flag ", cmd.Name()) + value[0]
|
||||
} else {
|
||||
ext = "_filedir -d"
|
||||
}
|
||||
@@ -335,7 +338,7 @@ func writeFlagHandler(buf *bytes.Buffer, name string, annotations map[string][]s
|
||||
}
|
||||
}
|
||||
|
||||
func writeShortFlag(buf *bytes.Buffer, flag *pflag.Flag) {
|
||||
func writeShortFlag(buf *bytes.Buffer, flag *pflag.Flag, cmd *Command) {
|
||||
name := flag.Shorthand
|
||||
format := " "
|
||||
if len(flag.NoOptDefVal) == 0 {
|
||||
@@ -343,10 +346,10 @@ func writeShortFlag(buf *bytes.Buffer, flag *pflag.Flag) {
|
||||
}
|
||||
format += "flags+=(\"-%s\")\n"
|
||||
buf.WriteString(fmt.Sprintf(format, name))
|
||||
writeFlagHandler(buf, "-"+name, flag.Annotations)
|
||||
writeFlagHandler(buf, "-"+name, flag.Annotations, cmd)
|
||||
}
|
||||
|
||||
func writeFlag(buf *bytes.Buffer, flag *pflag.Flag) {
|
||||
func writeFlag(buf *bytes.Buffer, flag *pflag.Flag, cmd *Command) {
|
||||
name := flag.Name
|
||||
format := " flags+=(\"--%s"
|
||||
if len(flag.NoOptDefVal) == 0 {
|
||||
@@ -354,7 +357,7 @@ func writeFlag(buf *bytes.Buffer, flag *pflag.Flag) {
|
||||
}
|
||||
format += "\")\n"
|
||||
buf.WriteString(fmt.Sprintf(format, name))
|
||||
writeFlagHandler(buf, "--"+name, flag.Annotations)
|
||||
writeFlagHandler(buf, "--"+name, flag.Annotations, cmd)
|
||||
}
|
||||
|
||||
func writeLocalNonPersistentFlag(buf *bytes.Buffer, flag *pflag.Flag) {
|
||||
@@ -380,9 +383,9 @@ func writeFlags(buf *bytes.Buffer, cmd *Command) {
|
||||
if nonCompletableFlag(flag) {
|
||||
return
|
||||
}
|
||||
writeFlag(buf, flag)
|
||||
writeFlag(buf, flag, cmd)
|
||||
if len(flag.Shorthand) > 0 {
|
||||
writeShortFlag(buf, flag)
|
||||
writeShortFlag(buf, flag, cmd)
|
||||
}
|
||||
if localNonPersistentFlags.Lookup(flag.Name) != nil {
|
||||
writeLocalNonPersistentFlag(buf, flag)
|
||||
@@ -392,9 +395,9 @@ func writeFlags(buf *bytes.Buffer, cmd *Command) {
|
||||
if nonCompletableFlag(flag) {
|
||||
return
|
||||
}
|
||||
writeFlag(buf, flag)
|
||||
writeFlag(buf, flag, cmd)
|
||||
if len(flag.Shorthand) > 0 {
|
||||
writeShortFlag(buf, flag)
|
||||
writeShortFlag(buf, flag, cmd)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -491,17 +494,20 @@ func (c *Command) GenBashCompletionFile(filename string) error {
|
||||
return c.GenBashCompletion(outFile)
|
||||
}
|
||||
|
||||
// MarkFlagRequired adds the BashCompOneRequiredFlag annotation to the named flag, if it exists.
|
||||
// MarkFlagRequired adds the BashCompOneRequiredFlag annotation to the named flag if it exists,
|
||||
// and causes your command to report an error if invoked without the flag.
|
||||
func (c *Command) MarkFlagRequired(name string) error {
|
||||
return MarkFlagRequired(c.Flags(), name)
|
||||
}
|
||||
|
||||
// MarkPersistentFlagRequired adds the BashCompOneRequiredFlag annotation to the named persistent flag, if it exists.
|
||||
// MarkPersistentFlagRequired adds the BashCompOneRequiredFlag annotation to the named persistent flag if it exists,
|
||||
// and causes your command to report an error if invoked without the flag.
|
||||
func (c *Command) MarkPersistentFlagRequired(name string) error {
|
||||
return MarkFlagRequired(c.PersistentFlags(), name)
|
||||
}
|
||||
|
||||
// MarkFlagRequired adds the BashCompOneRequiredFlag annotation to the named flag in the flag set, if it exists.
|
||||
// MarkFlagRequired adds the BashCompOneRequiredFlag annotation to the named flag if it exists,
|
||||
// and causes your command to report an error if invoked without the flag.
|
||||
func MarkFlagRequired(flags *pflag.FlagSet, name string) error {
|
||||
return flags.SetAnnotation(name, BashCompOneRequiredFlag, []string{"true"})
|
||||
}
|
||||
|
||||
5
vendor/github.com/spf13/cobra/bash_completions_test.go
сгенерированный
поставляемый
5
vendor/github.com/spf13/cobra/bash_completions_test.go
сгенерированный
поставляемый
@@ -2,6 +2,7 @@ package cobra
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
@@ -146,11 +147,11 @@ func TestBashCompletions(t *testing.T) {
|
||||
// check for filename extension flags
|
||||
check(t, output, `must_have_one_noun+=("three")`)
|
||||
// check for filename extension flags
|
||||
check(t, output, `flags_completion+=("__handle_filename_extension_flag json|yaml|yml")`)
|
||||
check(t, output, fmt.Sprintf(`flags_completion+=("__%s_handle_filename_extension_flag json|yaml|yml")`, rootCmd.Name()))
|
||||
// check for custom flags
|
||||
check(t, output, `flags_completion+=("__complete_custom")`)
|
||||
// check for subdirs_in_dir flags
|
||||
check(t, output, `flags_completion+=("__handle_subdirs_in_dir_flag themes")`)
|
||||
check(t, output, fmt.Sprintf(`flags_completion+=("__%s_handle_subdirs_in_dir_flag themes")`, rootCmd.Name()))
|
||||
|
||||
checkOmit(t, output, deprecatedCmd.Name())
|
||||
|
||||
|
||||
25
vendor/github.com/spf13/cobra/command.go
сгенерированный
поставляемый
25
vendor/github.com/spf13/cobra/command.go
сгенерированный
поставляемый
@@ -147,6 +147,11 @@ type Command struct {
|
||||
commandsMaxNameLen int
|
||||
// commandsAreSorted defines, if command slice are sorted or not.
|
||||
commandsAreSorted bool
|
||||
// commandCalledAs is the name or alias value used to call this command.
|
||||
commandCalledAs struct {
|
||||
name string
|
||||
called bool
|
||||
}
|
||||
|
||||
// args is actual args parsed from flags.
|
||||
args []string
|
||||
@@ -557,6 +562,7 @@ func (c *Command) findNext(next string) *Command {
|
||||
matches := make([]*Command, 0)
|
||||
for _, cmd := range c.commands {
|
||||
if cmd.Name() == next || cmd.HasAlias(next) {
|
||||
cmd.commandCalledAs.name = next
|
||||
return cmd
|
||||
}
|
||||
if EnablePrefixMatching && cmd.hasNameOrAliasPrefix(next) {
|
||||
@@ -567,6 +573,7 @@ func (c *Command) findNext(next string) *Command {
|
||||
if len(matches) == 1 {
|
||||
return matches[0]
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -828,6 +835,11 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
|
||||
return c, err
|
||||
}
|
||||
|
||||
cmd.commandCalledAs.called = true
|
||||
if cmd.commandCalledAs.name == "" {
|
||||
cmd.commandCalledAs.name = cmd.Name()
|
||||
}
|
||||
|
||||
err = cmd.execute(flags)
|
||||
if err != nil {
|
||||
// Always show help if requested, even if SilenceErrors is in
|
||||
@@ -1135,14 +1147,25 @@ func (c *Command) HasAlias(s string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// CalledAs returns the command name or alias that was used to invoke
|
||||
// this command or an empty string if the command has not been called.
|
||||
func (c *Command) CalledAs() string {
|
||||
if c.commandCalledAs.called {
|
||||
return c.commandCalledAs.name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// hasNameOrAliasPrefix returns true if the Name or any of aliases start
|
||||
// with prefix
|
||||
func (c *Command) hasNameOrAliasPrefix(prefix string) bool {
|
||||
if strings.HasPrefix(c.Name(), prefix) {
|
||||
c.commandCalledAs.name = c.Name()
|
||||
return true
|
||||
}
|
||||
for _, alias := range c.Aliases {
|
||||
if strings.HasPrefix(alias, prefix) {
|
||||
c.commandCalledAs.name = alias
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -1245,7 +1268,7 @@ func (c *Command) HasParent() bool {
|
||||
return c.parent != nil
|
||||
}
|
||||
|
||||
// GlobalNormalizationFunc returns the global normalization function or nil if doesn't exists.
|
||||
// GlobalNormalizationFunc returns the global normalization function or nil if it doesn't exist.
|
||||
func (c *Command) GlobalNormalizationFunc() func(f *flag.FlagSet, name string) flag.NormalizedName {
|
||||
return c.globNormFunc
|
||||
}
|
||||
|
||||
63
vendor/github.com/spf13/cobra/command_test.go
сгенерированный
поставляемый
63
vendor/github.com/spf13/cobra/command_test.go
сгенерированный
поставляемый
@@ -1563,3 +1563,66 @@ func TestUpdateName(t *testing.T) {
|
||||
t.Error("c.Name() should be updated on changed c.Use")
|
||||
}
|
||||
}
|
||||
|
||||
type calledAsTestcase struct {
|
||||
args []string
|
||||
call string
|
||||
want string
|
||||
epm bool
|
||||
tc bool
|
||||
}
|
||||
|
||||
func (tc *calledAsTestcase) test(t *testing.T) {
|
||||
defer func(ov bool) { EnablePrefixMatching = ov }(EnablePrefixMatching)
|
||||
EnablePrefixMatching = tc.epm
|
||||
|
||||
var called *Command
|
||||
run := func(c *Command, _ []string) { t.Logf("called: %q", c.Name()); called = c }
|
||||
|
||||
parent := &Command{Use: "parent", Run: run}
|
||||
child1 := &Command{Use: "child1", Run: run, Aliases: []string{"this"}}
|
||||
child2 := &Command{Use: "child2", Run: run, Aliases: []string{"that"}}
|
||||
|
||||
parent.AddCommand(child1)
|
||||
parent.AddCommand(child2)
|
||||
parent.SetArgs(tc.args)
|
||||
|
||||
output := new(bytes.Buffer)
|
||||
parent.SetOutput(output)
|
||||
|
||||
parent.Execute()
|
||||
|
||||
if called == nil {
|
||||
if tc.call != "" {
|
||||
t.Errorf("missing expected call to command: %s", tc.call)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if called.Name() != tc.call {
|
||||
t.Errorf("called command == %q; Wanted %q", called.Name(), tc.call)
|
||||
} else if got := called.CalledAs(); got != tc.want {
|
||||
t.Errorf("%s.CalledAs() == %q; Wanted: %q", tc.call, got, tc.want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCalledAs(t *testing.T) {
|
||||
tests := map[string]calledAsTestcase{
|
||||
"find/no-args": {nil, "parent", "parent", false, false},
|
||||
"find/real-name": {[]string{"child1"}, "child1", "child1", false, false},
|
||||
"find/full-alias": {[]string{"that"}, "child2", "that", false, false},
|
||||
"find/part-no-prefix": {[]string{"thi"}, "", "", false, false},
|
||||
"find/part-alias": {[]string{"thi"}, "child1", "this", true, false},
|
||||
"find/conflict": {[]string{"th"}, "", "", true, false},
|
||||
"traverse/no-args": {nil, "parent", "parent", false, true},
|
||||
"traverse/real-name": {[]string{"child1"}, "child1", "child1", false, true},
|
||||
"traverse/full-alias": {[]string{"that"}, "child2", "that", false, true},
|
||||
"traverse/part-no-prefix": {[]string{"thi"}, "", "", false, true},
|
||||
"traverse/part-alias": {[]string{"thi"}, "child1", "this", true, true},
|
||||
"traverse/conflict": {[]string{"th"}, "", "", true, true},
|
||||
}
|
||||
|
||||
for name, tc := range tests {
|
||||
t.Run(name, tc.test)
|
||||
}
|
||||
}
|
||||
|
||||
128
vendor/github.com/spf13/pflag/duration_slice.go
сгенерированный
поставляемый
Обычный файл
128
vendor/github.com/spf13/pflag/duration_slice.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,128 @@
|
||||
package pflag
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// -- durationSlice Value
|
||||
type durationSliceValue struct {
|
||||
value *[]time.Duration
|
||||
changed bool
|
||||
}
|
||||
|
||||
func newDurationSliceValue(val []time.Duration, p *[]time.Duration) *durationSliceValue {
|
||||
dsv := new(durationSliceValue)
|
||||
dsv.value = p
|
||||
*dsv.value = val
|
||||
return dsv
|
||||
}
|
||||
|
||||
func (s *durationSliceValue) Set(val string) error {
|
||||
ss := strings.Split(val, ",")
|
||||
out := make([]time.Duration, len(ss))
|
||||
for i, d := range ss {
|
||||
var err error
|
||||
out[i], err = time.ParseDuration(d)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
if !s.changed {
|
||||
*s.value = out
|
||||
} else {
|
||||
*s.value = append(*s.value, out...)
|
||||
}
|
||||
s.changed = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *durationSliceValue) Type() string {
|
||||
return "durationSlice"
|
||||
}
|
||||
|
||||
func (s *durationSliceValue) String() string {
|
||||
out := make([]string, len(*s.value))
|
||||
for i, d := range *s.value {
|
||||
out[i] = fmt.Sprintf("%s", d)
|
||||
}
|
||||
return "[" + strings.Join(out, ",") + "]"
|
||||
}
|
||||
|
||||
func durationSliceConv(val string) (interface{}, error) {
|
||||
val = strings.Trim(val, "[]")
|
||||
// Empty string would cause a slice with one (empty) entry
|
||||
if len(val) == 0 {
|
||||
return []time.Duration{}, nil
|
||||
}
|
||||
ss := strings.Split(val, ",")
|
||||
out := make([]time.Duration, len(ss))
|
||||
for i, d := range ss {
|
||||
var err error
|
||||
out[i], err = time.ParseDuration(d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// GetDurationSlice returns the []time.Duration value of a flag with the given name
|
||||
func (f *FlagSet) GetDurationSlice(name string) ([]time.Duration, error) {
|
||||
val, err := f.getFlagType(name, "durationSlice", durationSliceConv)
|
||||
if err != nil {
|
||||
return []time.Duration{}, err
|
||||
}
|
||||
return val.([]time.Duration), nil
|
||||
}
|
||||
|
||||
// DurationSliceVar defines a durationSlice flag with specified name, default value, and usage string.
|
||||
// The argument p points to a []time.Duration variable in which to store the value of the flag.
|
||||
func (f *FlagSet) DurationSliceVar(p *[]time.Duration, name string, value []time.Duration, usage string) {
|
||||
f.VarP(newDurationSliceValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// DurationSliceVarP is like DurationSliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) DurationSliceVarP(p *[]time.Duration, name, shorthand string, value []time.Duration, usage string) {
|
||||
f.VarP(newDurationSliceValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
||||
// DurationSliceVar defines a duration[] flag with specified name, default value, and usage string.
|
||||
// The argument p points to a duration[] variable in which to store the value of the flag.
|
||||
func DurationSliceVar(p *[]time.Duration, name string, value []time.Duration, usage string) {
|
||||
CommandLine.VarP(newDurationSliceValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// DurationSliceVarP is like DurationSliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func DurationSliceVarP(p *[]time.Duration, name, shorthand string, value []time.Duration, usage string) {
|
||||
CommandLine.VarP(newDurationSliceValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
||||
// DurationSlice defines a []time.Duration flag with specified name, default value, and usage string.
|
||||
// The return value is the address of a []time.Duration variable that stores the value of the flag.
|
||||
func (f *FlagSet) DurationSlice(name string, value []time.Duration, usage string) *[]time.Duration {
|
||||
p := []time.Duration{}
|
||||
f.DurationSliceVarP(&p, name, "", value, usage)
|
||||
return &p
|
||||
}
|
||||
|
||||
// DurationSliceP is like DurationSlice, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) DurationSliceP(name, shorthand string, value []time.Duration, usage string) *[]time.Duration {
|
||||
p := []time.Duration{}
|
||||
f.DurationSliceVarP(&p, name, shorthand, value, usage)
|
||||
return &p
|
||||
}
|
||||
|
||||
// DurationSlice defines a []time.Duration flag with specified name, default value, and usage string.
|
||||
// The return value is the address of a []time.Duration variable that stores the value of the flag.
|
||||
func DurationSlice(name string, value []time.Duration, usage string) *[]time.Duration {
|
||||
return CommandLine.DurationSliceP(name, "", value, usage)
|
||||
}
|
||||
|
||||
// DurationSliceP is like DurationSlice, but accepts a shorthand letter that can be used after a single dash.
|
||||
func DurationSliceP(name, shorthand string, value []time.Duration, usage string) *[]time.Duration {
|
||||
return CommandLine.DurationSliceP(name, shorthand, value, usage)
|
||||
}
|
||||
165
vendor/github.com/spf13/pflag/duration_slice_test.go
сгенерированный
поставляемый
Обычный файл
165
vendor/github.com/spf13/pflag/duration_slice_test.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,165 @@
|
||||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code ds governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package pflag
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func setUpDSFlagSet(dsp *[]time.Duration) *FlagSet {
|
||||
f := NewFlagSet("test", ContinueOnError)
|
||||
f.DurationSliceVar(dsp, "ds", []time.Duration{}, "Command separated list!")
|
||||
return f
|
||||
}
|
||||
|
||||
func setUpDSFlagSetWithDefault(dsp *[]time.Duration) *FlagSet {
|
||||
f := NewFlagSet("test", ContinueOnError)
|
||||
f.DurationSliceVar(dsp, "ds", []time.Duration{0, 1}, "Command separated list!")
|
||||
return f
|
||||
}
|
||||
|
||||
func TestEmptyDS(t *testing.T) {
|
||||
var ds []time.Duration
|
||||
f := setUpDSFlagSet(&ds)
|
||||
err := f.Parse([]string{})
|
||||
if err != nil {
|
||||
t.Fatal("expected no error; got", err)
|
||||
}
|
||||
|
||||
getDS, err := f.GetDurationSlice("ds")
|
||||
if err != nil {
|
||||
t.Fatal("got an error from GetDurationSlice():", err)
|
||||
}
|
||||
if len(getDS) != 0 {
|
||||
t.Fatalf("got ds %v with len=%d but expected length=0", getDS, len(getDS))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDS(t *testing.T) {
|
||||
var ds []time.Duration
|
||||
f := setUpDSFlagSet(&ds)
|
||||
|
||||
vals := []string{"1ns", "2ms", "3m", "4h"}
|
||||
arg := fmt.Sprintf("--ds=%s", strings.Join(vals, ","))
|
||||
err := f.Parse([]string{arg})
|
||||
if err != nil {
|
||||
t.Fatal("expected no error; got", err)
|
||||
}
|
||||
for i, v := range ds {
|
||||
d, err := time.ParseDuration(vals[i])
|
||||
if err != nil {
|
||||
t.Fatalf("got error: %v", err)
|
||||
}
|
||||
if d != v {
|
||||
t.Fatalf("expected ds[%d] to be %s but got: %d", i, vals[i], v)
|
||||
}
|
||||
}
|
||||
getDS, err := f.GetDurationSlice("ds")
|
||||
if err != nil {
|
||||
t.Fatalf("got error: %v", err)
|
||||
}
|
||||
for i, v := range getDS {
|
||||
d, err := time.ParseDuration(vals[i])
|
||||
if err != nil {
|
||||
t.Fatalf("got error: %v", err)
|
||||
}
|
||||
if d != v {
|
||||
t.Fatalf("expected ds[%d] to be %s but got: %d from GetDurationSlice", i, vals[i], v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDSDefault(t *testing.T) {
|
||||
var ds []time.Duration
|
||||
f := setUpDSFlagSetWithDefault(&ds)
|
||||
|
||||
vals := []string{"0s", "1ns"}
|
||||
|
||||
err := f.Parse([]string{})
|
||||
if err != nil {
|
||||
t.Fatal("expected no error; got", err)
|
||||
}
|
||||
for i, v := range ds {
|
||||
d, err := time.ParseDuration(vals[i])
|
||||
if err != nil {
|
||||
t.Fatalf("got error: %v", err)
|
||||
}
|
||||
if d != v {
|
||||
t.Fatalf("expected ds[%d] to be %d but got: %d", i, d, v)
|
||||
}
|
||||
}
|
||||
|
||||
getDS, err := f.GetDurationSlice("ds")
|
||||
if err != nil {
|
||||
t.Fatal("got an error from GetDurationSlice():", err)
|
||||
}
|
||||
for i, v := range getDS {
|
||||
d, err := time.ParseDuration(vals[i])
|
||||
if err != nil {
|
||||
t.Fatal("got an error from GetDurationSlice():", err)
|
||||
}
|
||||
if d != v {
|
||||
t.Fatalf("expected ds[%d] to be %d from GetDurationSlice but got: %d", i, d, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDSWithDefault(t *testing.T) {
|
||||
var ds []time.Duration
|
||||
f := setUpDSFlagSetWithDefault(&ds)
|
||||
|
||||
vals := []string{"1ns", "2ns"}
|
||||
arg := fmt.Sprintf("--ds=%s", strings.Join(vals, ","))
|
||||
err := f.Parse([]string{arg})
|
||||
if err != nil {
|
||||
t.Fatal("expected no error; got", err)
|
||||
}
|
||||
for i, v := range ds {
|
||||
d, err := time.ParseDuration(vals[i])
|
||||
if err != nil {
|
||||
t.Fatalf("got error: %v", err)
|
||||
}
|
||||
if d != v {
|
||||
t.Fatalf("expected ds[%d] to be %d but got: %d", i, d, v)
|
||||
}
|
||||
}
|
||||
|
||||
getDS, err := f.GetDurationSlice("ds")
|
||||
if err != nil {
|
||||
t.Fatal("got an error from GetDurationSlice():", err)
|
||||
}
|
||||
for i, v := range getDS {
|
||||
d, err := time.ParseDuration(vals[i])
|
||||
if err != nil {
|
||||
t.Fatalf("got error: %v", err)
|
||||
}
|
||||
if d != v {
|
||||
t.Fatalf("expected ds[%d] to be %d from GetDurationSlice but got: %d", i, d, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDSCalledTwice(t *testing.T) {
|
||||
var ds []time.Duration
|
||||
f := setUpDSFlagSet(&ds)
|
||||
|
||||
in := []string{"1ns,2ns", "3ns"}
|
||||
expected := []time.Duration{1, 2, 3}
|
||||
argfmt := "--ds=%s"
|
||||
arg1 := fmt.Sprintf(argfmt, in[0])
|
||||
arg2 := fmt.Sprintf(argfmt, in[1])
|
||||
err := f.Parse([]string{arg1, arg2})
|
||||
if err != nil {
|
||||
t.Fatal("expected no error; got", err)
|
||||
}
|
||||
for i, v := range ds {
|
||||
if expected[i] != v {
|
||||
t.Fatalf("expected ds[%d] to be %d but got: %d", i, expected[i], v)
|
||||
}
|
||||
}
|
||||
}
|
||||
Ссылка в новой задаче
Block a user