You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The piece of code described below is meant to define different cmd flags with their default values.
However, it defines them with actual value of the flag as its default value.
returnnil, fmt.Errorf("unexpected cli value type: %T", values[i])
}
}
Right after this is the code, that is meant to actually set the value. But because we have already used the actual values as default values, this codes ends up not having any impact.
returnnil, fmt.Errorf("failed to set cli flag: %T", flags[i])
}
default:
returnnil, fmt.Errorf("unexpected cli value type: %T", values[i])
}
}
In general, this does not create any problems, but it did when I was trying to add a StringSliceFlag. This is because unlike other flags, StringSlice appends values to existing values when we do StringSlice.Set, while others would overwrite it.
What to change:-
A simpler way would be to use default values of each type like false for bool, 0 for int etc. These are not the true default values for the flag, but it would hurt since we are dealing with tests and all the values would be set later.
Other way is to have a map of flag name to default value and use that to set default values.
Other information and links
The text was updated successfully, but these errors were encountered:
Issue summary
The piece of code described below is meant to define different cmd flags with their default values.
However, it defines them with actual value of the flag as its default value.
gossamer/cmd/gossamer/utils_test.go
Lines 33 to 46 in bf903f2
Right after this is the code, that is meant to actually set the value. But because we have already used the actual values as default values, this codes ends up not having any impact.
gossamer/cmd/gossamer/utils_test.go
Lines 50 to 82 in bf903f2
In general, this does not create any problems, but it did when I was trying to add a
StringSliceFlag
. This is because unlike other flags, StringSlice appends values to existing values when we do StringSlice.Set, while others would overwrite it.What to change:-
A simpler way would be to use default values of each type like false for bool, 0 for int etc. These are not the true default values for the flag, but it would hurt since we are dealing with tests and all the values would be set later.
Other way is to have a map of flag name to default value and use that to set default values.
Other information and links
The text was updated successfully, but these errors were encountered: