fix tests

This commit is contained in:
Roberto Hidalgo 2022-12-31 18:07:54 -06:00
parent a4b16336c7
commit 0d24a80075
2 changed files with 17 additions and 8 deletions

View File

@ -38,6 +38,19 @@ func (args *Arguments) AllKnownStr() map[string]string {
return col return col
} }
func anySliceToStringSlice(src any) []string {
res := []string{}
switch d := src.(type) {
case []string:
res = d
case []any:
for _, valI := range d {
res = append(res, valI.(string))
}
}
return res
}
func (args *Arguments) Parse(supplied []string) { func (args *Arguments) Parse(supplied []string) {
for idx, arg := range *args { for idx, arg := range *args {
argumentProvided := idx < len(supplied) argumentProvided := idx < len(supplied)
@ -45,11 +58,7 @@ func (args *Arguments) Parse(supplied []string) {
if !argumentProvided { if !argumentProvided {
if arg.Default != nil { if arg.Default != nil {
if arg.Variadic { if arg.Variadic {
defaultSlice := arg.Default.([]string) defaultSlice := anySliceToStringSlice(arg.Default)
// defaultSlice := []string{}
// for _, valI := range arg.Default.([]string) {
// defaultSlice = append(defaultSlice, valI.(string))
// }
arg.provided = &defaultSlice arg.provided = &defaultSlice
} else { } else {
defaultString := arg.Default.(string) defaultString := arg.Default.(string)
@ -185,7 +194,7 @@ func (arg *Argument) ToValue() any {
} else { } else {
if arg.Default != nil { if arg.Default != nil {
if arg.Variadic { if arg.Variadic {
defaultSlice := arg.Default defaultSlice := anySliceToStringSlice(arg.Default)
// for _, valI := range arg.Default.([]any) { // for _, valI := range arg.Default.([]any) {
// valStr := valI.(string) // valStr := valI.(string)
// defaultSlice = append(defaultSlice, valStr) // defaultSlice = append(defaultSlice, valStr)

View File

@ -28,9 +28,9 @@ func TestEnabled(t *testing.T) {
Expects: true, Expects: true,
}, },
{ {
Name: env.Verbose, Name: env.Silent,
Func: SilenceEnabled, Func: SilenceEnabled,
Expects: false, Expects: true,
}, },
{ {
Name: env.ValidationDisabled, Name: env.ValidationDisabled,