Add functionality to support errors.Is on all generated errors to keep
in line with best practice on checking whether an error is of the
specified type as per changes to error handling in go1.13.
* fix isPathShadowedInFlatMap type cast bug
* Add "IsPathShadowedInFlatMap" method unit test
* fix: typo
* add an unit test for flag shadow
---------
Co-authored-by: Márk Sági-Kazár <sagikazarmark@users.noreply.github.com>
We have encountered numerous places where it is convenient to have viper return a `uint16` value, especially in combination with the new `netip` package that represents a port correctly as `uint16` rather than just an `int`. cobra already supports this, but we need a conversion from the existing `GetUint` method in viper.
When merging a key where the target value is nil, the type of the target
and source do not match. What currently happens is an error is logged
and the key is skipped.
I have changed it so that it does the same thing as when the target key
is missing: copy the source value to the target.
Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
* Added support for accessing slices
* Processed PR feedback
- renamed searchMapWithPathPrefixes to searchIndexableWithPathPrefixes
- moved source type specific search logic to speparate functions
- Inverted if statments to avoid the arrow pattern
* Quickly return from searchSliceWithPathPrefixes and searchMapWithPathPrefixes functions without intermediate variables
Mapstructure so far returned nil for empty string slices.
In a recent version this bug has been fixed:
https://github.com/mitchellh/mapstructure/pull/155
Incidentally, this was a bug in Viper too:
GetStringSlice and Unmarshal returned with different values.
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This change modifies BindEnv to permit a list of environment variable
names in order to support multiple env. vars. for the same config key.
When this form is used, env. keys take precedence in the written order.
Closes#971
* add parsing for stringToString flags
* add logic to return flags default if not val set, add a test
* extract parsing into single func
* add a few more cases
* return nil if unable to parse instead of panicing
* return map[string]interface in order to work with cast.ToStringMap
* mostly copy pflags implementation of the conversion to a stringtostring
* Add support to save file with no extension
The support introduced for files with no file extension is only partial as trying to save the config file would fail with `<file name> requires valid extension`
This adds support to saving such files
* Only consider files without extension if the config type is explicitly specified
* Hides unused variable in test
* First check for config type then for file without extension