Commit graph

29 commits

Author SHA1 Message Date
Adrian Maurer
ed154ee610
fix: conflicts 2021-09-21 10:15:26 -04:00
John Gosset
3826be3135 Simplify $HOME prefix check 2020-07-31 23:39:06 +02:00
João Abecasis
ce534045f9 Fix environment variable expansion in absPathify
- Don't expand user home directory for variable names that simply have a
  HOME prefix;
- Support expansion of variables not followed by the path separator.
2020-07-31 23:39:06 +02:00
Mark Sagi-Kazar
eabbc68a3e Fix file path lookup 2019-12-06 17:29:42 +01:00
Andrew Stuart
62edee3196
Revert "Cater for case-sensitive dependencies (#463)"
This reverts commit b56071875a.
2018-09-29 21:41:27 -07:00
Panagiotis Moustafellos
b56071875a Cater for case-sensitive dependencies (#463)
Switching jww from jwalterweatherman to jWalterWeatherman for cases when vgo is broken
2018-09-29 20:32:38 -07:00
Adam Sherwood
1a0c4a370c Feature/write config (#287)
* Added method to write into TOML file.

* Added functionality to export configuration based on config type. The feature supports JSON and TOML.

* Added method to write into YAML file.

* Fixed the issue of incorrect defer and error checking order. The error checking must be first otherwise it will cause panic.

* Add WriteConfig methods

* Add support for toml

* Add shared write function and safe methods

* Fix incorrectly modified imports

* Remove extra comments

* Fix spelling

* Make marshal spelling consistent throughout

* Add support for remaining configuration types

This commit moves a significant portion of the code back to viper.go to
facilitate having access to the object when reading the files. The purpose is to
add properties to the viper object at read time, so that we can add the comments
back to the file when writing.

* Add tests for each written file type

* Modify test for updated HCL specification

* Modify to only support HCL write in Go 1.7

* Revert "Modify to only support HCL write in Go 1.7"

This reverts commit 12b34bc4eb92cbf8ebfd56b79519f448607e3e51.

* Need to truncate the file before writing

* Write all settings including overrides

* Use filename variable

* Lint remote.go

* Fix toml return count error
2017-12-06 23:26:31 -05:00
Jeff Lindsay
4dddf7c62e Allow exists util function to take afero.Fs so it can be used with non-deafult instances of Viper (#405)
Signed-off-by: Jeff Lindsay <progrium@gmail.com>
2017-11-09 21:57:16 +01:00
Bjørn Erik Pedersen
80ab6657f9 Copy and insensitivise maps in Set
Fixes #261
Closes #265
2016-10-24 21:20:41 +02:00
Benoît Masson
50515b700e Increase performance of nested keys search
* Fixed: insensitiviseMaps and tests

All keys (even nested ones) are now lower-cased recursively.

On the way, map[interface{}]interface{} are cast to map[string]interface{}

* Changed: simplified find() fast path and increase performance

Removed searchMapForKey(), fast path directly integrated into searchMap() and
searchMapWithPathPrefixes()
=> more generic (searchMapForKey() wasn't called everywhere it should have)

At the same time, significantly speed up searchMap() and searchMapWithPathPrefixes(),
which are still used for nested keys: the assumption that map keys are all
lower-cased allows to perform
    val = m[key]
instead of
    for k, v := range m {
      if strings.ToLower(k) == strings.ToLower(key) {
        val = v
      }
    }
=> i.e., directly access the map instead of enumerate the keys
2016-10-14 11:24:45 +02:00
Benoît Masson
ec4eb2fa85 Nested maps (#195)
Fixes #71, #93, #158, #168, #209, #141, #160, #162, #190

* Fixed: indentation in comment
* Fixed: Get() returns nil when nested element not found
* Fixed: insensitiviseMaps() made recursive so that nested keys are lowercased
* Fixed: order of expected<=>actual in assert.Equal() statements
* Fixed: find() looks into "overrides" first
* Fixed: TestBindPFlags() to use a new Viper instance
* Fixed: removed extra aliases from display in Debug()
* Added: test for checking precedence of dot-containing keys.
* Fixed: Set() and SetDefault() insert nested values
* Added: tests for overriding nested values
* Changed: AllKeys() includes all keys / AllSettings() includes overridden nested values
* Added: test for shadowed nested key
* Fixed: properties parsing generates nested maps
* Fixed: Get() and IsSet() work correctly on nested values
* Changed: modifier README.md to reflect changes
2016-10-08 10:00:18 +02:00
Albert
a78f70b5b9 Small refactorings (#230)
* Fix typo in description of UnmarshalExact
* Omit 2nd values from range loops
* Delete findCWD method from util (was unused)
* Edit documentation according to golint
* Fix documentation in util
* Use RemoteProvider interface instead of defaultRemoteProvider
* Fix err variable in BindFlagValues
2016-09-20 10:17:41 +02:00
Vladimir Vivien
7fb2782df3 Handle TOML Library Licensing
This patch updates the package used for parsing TOML content from
"github.com/BurntSushi/toml" to "github.com/pelletier/go-toml" as the
latter uses a more accepted OSS license (MIT), enabling the inclusion of
Viper or projects that depend on Viper in projects that have licensing
requirements incongruent with the license of the previous TOML package.

Closes #228
Closes #225
Fixes #179
2016-08-20 20:00:39 +01:00
Bjørn Erik Pedersen
abafbf243b Revert "Handle TOML Library Licensing"
It breaks Hugo, will have to test/investigate.

Erro when building Hugo docs:
```
ERROR: 2016/08/05 11:19:23 site.go:1208: unable to process menus in site config
ERROR: 2016/08/05 11:19:23 site.go:1209: Unable to Cast map[string]interface {}{"pre":"<i class='fa fa-space-shuttle'></i>", "weight":-20, "url":"/commands/", "name":"Hugo Cmd Reference", "identifier":"commands"} of type map[string]interface {} to []interface{}
```

This reverts commit 7402856f06.
2016-08-05 11:21:53 +02:00
Bjørn Erik Pedersen
a59dcccc82 Move the Afero fs to the Viper type
And make a exported setter for it.
2016-08-05 09:45:58 +02:00
Matthieu Grieger
4cf0bd2789 Add support for Afero filesystems 2016-08-05 09:24:49 +02:00
Schley Andrew Kutz
7402856f06 Handle TOML Library Licensing
This patch updates the package used for parsing TOML content from
"github.com/BurntSushi/toml" to "github.com/pelletier/go-toml" as the
latter uses a more accepted OSS license (MIT), enabling the inclusion of
Viper or projects that depend on Viper in projects that have licensing
requirements incongruent with the license of the previous TOML package.

This patch replaces the PR https://github.com/spf13/viper/pull/208 after
discussing the matter with @spf13 and deciding to update the TOML parser
instead of making TOML build-optional.
2016-08-05 09:15:24 +02:00
patdhlk
606a4f3933 add support for hcl 2015-12-15 14:44:21 -05:00
Matt Surabian
1967d93db7 Fixed #36: Changed Marshal to Unmarshal throughout. 2015-09-08 08:24:57 -04:00
Vlad Didenko
fa137328f6 Fixed #68 2015-08-17 00:09:59 -05:00
oliveagle
2a7f7f40fc add README.md, and fix strings.ToLower(configType) 2015-05-19 10:07:21 -04:00
bep
be782f3fee Revert "Recursively insensitivize the configuration structures"
This reverts commit 8d9577a72e.

The commit is reasonable enough, but this is a major breaking change for Hugo.

We have to figure out how to handle this before we introduce this one.

See https://github.com/spf13/hugo/issues/1129
2015-05-11 23:36:48 +02:00
Kiril Zvezdarov
8d9577a72e Recursively insensitivize the configuration structures 2015-05-01 22:52:16 -04:00
Wayne Walker
ba3382dd23 59 - add properties file support to viper 2015-04-14 13:15:02 -05:00
Daniel Eloff
e133904c4f Add GetSizeInBytes.
Useful to parse strings like 1GB or 12 mb into an unsigned integer number of bytes.
2015-03-12 22:19:13 -04:00
Anthony Fok
5b0b926e3d :%s/insensativiseMap/insensitiviseMap/g 2015-03-07 04:04:19 -07:00
Anthony Fok
82cbb7dec7 Upgrade from gopkg.in/yaml.v1 to gopkg.in/yaml.v2 2015-02-16 19:32:47 -05:00
spf13
18a87c05c6 Adding documentation inline. Moving Reset() to viper_test.go 2014-12-05 17:04:40 +01:00
spf13
29f1858f87 Viper now supports multiple vipers. No API changes. 2014-12-05 03:55:51 +01:00