Commit graph

222 commits

Author SHA1 Message Date
Adam Sherwood
c0c02c2345 Sync fork with upstream 2017-12-01 18:52:52 -08: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
Kamil Wargula
8ef37cbca7 Fix incorrect name of function in README.md
Change `SetEnvReplacer` to `SetEnvKeyReplacer`
2017-10-20 12:40:09 +02:00
Bjørn Erik Pedersen
d9cca5ef33 Go fmt viper.go 2017-09-29 23:06:42 +02:00
Alexander Krasnukhin
266e588e9e Add string slice support to defaultDecoderConfig
This way it correctly decodes string slices as well.
2017-09-29 21:44:38 +02:00
Adam Sherwood
3dfbd2fccd Merge branch 'master' into feature/write-config
Syncing with upstream
2017-08-30 09:59:01 -07:00
JG²
25b30aa063 Add Clairctl as a Go project that uses Viper
See #354
2017-07-22 23:52:07 -06:00
Nick Miyake
8ac2e2e20f Run gofmt on all existing code
Also:

* Add check to .travis.yml that verifies that all code is gofmt-compliant
* Touch up some newlines

See #351
2017-07-22 23:47:47 -06:00
Nick Miyake
f257d19100 Fix a few minor typos/formatting issues with comments
See #350
2017-07-22 23:39:01 -06:00
Brad Peabody
04691bc570 Improve documentation for flags
See #329
2017-07-22 23:26:21 -06:00
Nikola Kovacs
9766537120 Fix grammar/typo in comment for getEnv()
See #310
2017-07-22 23:09:41 -06:00
Albert Nigmatzianov
16a9458573 Fix indentation in README.md
See #345
2017-07-22 22:54:24 -06:00
Anthony Fok
df7314a14e Make minor copy-editing changes to README.md 2017-07-21 04:20:10 -06:00
Albert Nigmatzianov
c1de95864d Prevent redundant type assertion in Get
There is no need to assert variables which already have appropriate
type.

name              old time/op    new time/op    delta
GetBool-4            554ns ± 3%     493ns ± 8%  -10.86%  (p=0.000 n=14+15)
Get-4                484ns ± 4%     414ns ± 7%  -14.37%  (p=0.000 n=14+15)
GetBoolFromMap-4    8.38ns ± 6%    7.83ns ± 7%   -6.59%  (p=0.000 n=15+15)

name              old alloc/op   new alloc/op   delta
GetBool-4            65.0B ± 0%     64.0B ± 0%   -1.54%  (p=0.000 n=15+15)
Get-4                64.0B ± 0%     64.0B ± 0%     ~     (all equal)
GetBoolFromMap-4     0.00B          0.00B          ~     (all equal)

name              old allocs/op  new allocs/op  delta
GetBool-4             5.00 ± 0%      4.00 ± 0%  -20.00%  (p=0.000 n=15+15)
Get-4                 5.00 ± 0%      4.00 ± 0%  -20.00%  (p=0.000 n=15+15)
GetBoolFromMap-4      0.00           0.00          ~     (all equal)
2017-06-19 14:43:13 +02:00
Nick Miyake
a1ecfa6a20 Fix apostrophes in README
Fix "it's" -> "its".
2017-06-10 01:09:38 +02:00
Herkermer Sherwood
4b195d0ed8 Fix toml return count error 2017-04-23 14:00:53 -07:00
Herkermer Sherwood
c588a0c383 Lint remote.go 2017-04-23 13:43:38 -07:00
Herkermer Sherwood
760350d83c Use filename variable 2017-04-23 13:41:00 -07:00
Herkermer Sherwood
dceace525a Write all settings including overrides 2017-04-23 13:36:31 -07:00
Herkermer Sherwood
0ea954cb0d Need to truncate the file before writing 2017-04-23 13:36:31 -07:00
Herkermer Sherwood
543b9ec4c1 Revert "Modify to only support HCL write in Go 1.7"
This reverts commit 12b34bc4eb92cbf8ebfd56b79519f448607e3e51.
2017-04-23 13:36:31 -07:00
Herkermer Sherwood
01cef45259 Modify to only support HCL write in Go 1.7 2017-04-23 13:36:31 -07:00
Herkermer Sherwood
cf3aa482da Modify test for updated HCL specification 2017-04-23 13:36:31 -07:00
Herkermer Sherwood
6805b2ad85 Add tests for each written file type 2017-04-23 13:36:31 -07:00
Herkermer Sherwood
3a92f74e9b 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.
2017-04-23 13:36:31 -07:00
Herkermer Sherwood
315278c264 Make marshal spelling consistent throughout 2017-04-23 13:27:12 -07:00
Herkermer Sherwood
5b296abffb Fix spelling 2017-04-23 13:26:39 -07:00
Herkermer Sherwood
75bbdad0c3 Remove extra comments 2017-04-23 13:26:39 -07:00
Herkermer Sherwood
a694a73d31 Fix incorrectly modified imports 2017-04-23 13:26:39 -07:00
Herkermer Sherwood
5d10b9a48a Add shared write function and safe methods 2017-04-23 13:26:39 -07:00
Herkermer Sherwood
5ae581fbf7 Add support for toml 2017-04-23 13:26:08 -07:00
Herkermer Sherwood
e4c838dc30 Add WriteConfig methods 2017-04-23 13:26:08 -07:00
g3rk6
4c3baa4a94 Fixed the issue of incorrect defer and error checking order. The error checking must be first otherwise it will cause panic. 2017-04-23 13:17:26 -07:00
g3rk6
3611c6c1c4 Added method to write into YAML file. 2017-04-23 13:17:26 -07:00
g3rk6
71d6b8c96f Added functionality to export configuration based on config type. The feature supports JSON and TOML. 2017-04-23 13:16:48 -07:00
g3rk6
985fae64ee Added method to write into TOML file. 2017-04-23 13:16:09 -07:00
Paweł Szczur
0967fc9ace Properly handle string slice values 2017-04-17 10:08:15 +02:00
Miguel Eduardo Gil Biraud
5d46e70da8 Fix UnmarshalKey handling of time.Duration
* Failing test for key unmarshaling with nested structs containing time.Duration

* Fix UnmarshalKey to use of defaultDecoderConfig
2017-04-10 11:26:50 +02:00
Wolfgang Friedl
84f94806c6 Avoid the start of go-routines which are never get stopped 2017-03-15 14:43:09 +01:00
Bjørn Erik Pedersen
0b5690fd87 Revert "remote: Avoid the start of go-routines which are never get stopped"
This reverts commit 11ca61e888.
2017-03-15 08:10:26 +01:00
Wolfgang Friedl
11ca61e888 remote: Avoid the start of go-routines which are never get stopped 2017-03-15 08:08:46 +01:00
Bjørn Erik Pedersen
7538d73b4e travis: Bump to Go 1.7.5 and 1.8 (Yay!) 2017-02-17 17:38:17 +01:00
Cameron Moore
d90f2bb139 Only save config on success in ReadInConfig
If the user creates a invalid config file while watching for config
changes, the previous, valid config is not retained.  This commit only
overwrites the running config if unmarshalling was successful.
2017-02-17 17:31:47 +01:00
Kevin GEORGES
5ed0fc31f7 Fix MergeInConfig error return
UnsupportedConfigError was returned if config file not found

* Swap getConfigFile and getConfigType call
* Add a unit test
2016-12-13 10:38:49 +01:00
Albert Nigmatzianov
651d9d916a Document case-insensitivity for key taking methods 2016-10-29 23:33:52 +02: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
285f151019 Fixed AllKeys() to include env values added with BindEnv()
* Fixed: values bound with BindEnv added to AllKeys()

Cast was not working, and v.env wasn't used when merging keys.

Rewrote explicit and specific casts for maps storing strings or FlagValues.

* Added: test for BindEnv() and AllKeys()

To make sure AllSettings() and Unmarshal() will consider environment
variables added with BindEnv().
2016-10-23 23:04:21 +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
Jonathan Anderson
44208030b3 Allow errors to propagate from getConfigFile(). (#161)
- propagate ConfigFileNotFoundError instead of using unsupported config type error when config file is not found
2016-10-13 13:33:30 +02:00
Nils Landt
c14ce6d43c Correct FlagValue interface examples in Readme (#254)
`IsChanged` is actually named `HasChanged`, and the examples were missing function return declarations, so you couldn't just copy/paste it.
2016-10-12 11:40:13 +02:00