mirror of
https://github.com/wavetermdev/ssh_config.git
synced 2026-08-05 13:43:40 -07:00
change ClearCachedConfigs to ReloadConfigs
Clearing cached data is somewhat vague and could be more confusing to users who are not familiar with this library. But Reloading the config data is very straightforward. For this reason, the ability to clear the cache has been replaced with the ability to reload. The reload simply clears the cache and then loads the contents again. Additionally, this contains a bug fix that ensure the loadConfigs pointer is set to a non-null value before it is used.
This commit is contained in:
@@ -42,15 +42,14 @@ Some SSH arguments have default values - for example, the default value for
|
||||
given Host/keyword pair exists in the config, we'll return a default for the
|
||||
keyword if one exists.
|
||||
|
||||
### Clearing cached SSH config files
|
||||
### Reloading SSH config files
|
||||
Once the first call to `Get()`, `GetStrict()`, `GetAll()`, or `GetAllStrict()`
|
||||
has been made, the contents of the config files will be cached for all future
|
||||
calls to any of those functions. This cache can manually be cleared with the
|
||||
`ClearCachedConfigs()` function. Once this is done, it will be cached again by
|
||||
the next call to `Get()`, `GetStrict()`, `GetAll()`, or `GetAllStrict()`.
|
||||
calls to any of those functions. The `ReloadConfigs()` function will reset
|
||||
this cache and replace it with the current config file contents.
|
||||
|
||||
```go
|
||||
ssh_config.ClearCachedConfigs()
|
||||
ssh_config.ReloadConfigs()
|
||||
```
|
||||
|
||||
### Manipulating SSH config files
|
||||
|
||||
@@ -167,13 +167,12 @@ func GetAllStrict(alias, key string) ([]string, error) {
|
||||
return DefaultUserSettings.GetAllStrict(alias, key)
|
||||
}
|
||||
|
||||
// ClearCachedConfigs resets the loaded config so it can be reloaded on the
|
||||
// next retrieval.
|
||||
// ReloadConfigs clears the cached config data and freshly loads the config
|
||||
// files again.
|
||||
//
|
||||
// ClearCachedConfigs is a wrapper around
|
||||
// DefaultUserSettings.ClearCachedConfigs.
|
||||
func ClearCachedConfigs() {
|
||||
DefaultUserSettings.ClearCachedConfigs()
|
||||
// ReloadConfigs is a wrapper around DefaultUserSettings.ReloadConfigs.
|
||||
func ReloadConfigs() {
|
||||
DefaultUserSettings.ReloadConfigs()
|
||||
}
|
||||
|
||||
// Get finds the first value for key within a declaration that matches the
|
||||
@@ -281,6 +280,9 @@ func (u *UserSettings) ConfigFinder(f func() string) {
|
||||
}
|
||||
|
||||
func (u *UserSettings) doLoadConfigs() {
|
||||
if u.loadConfigs == nil {
|
||||
u.loadConfigs = new(sync.Once)
|
||||
}
|
||||
u.loadConfigs.Do(func() {
|
||||
var filename string
|
||||
var err error
|
||||
@@ -319,10 +321,11 @@ func (u *UserSettings) doLoadConfigs() {
|
||||
})
|
||||
}
|
||||
|
||||
// ClearCachedConfigs resets the loaded config so it can be reloaded on the
|
||||
// next retrieval.
|
||||
func (u *UserSettings) ClearCachedConfigs() {
|
||||
// ReloadConfigs clears the cached config data and freshly loads the config
|
||||
// files again.
|
||||
func (u *UserSettings) ReloadConfigs() {
|
||||
u.loadConfigs = new(sync.Once)
|
||||
u.doLoadConfigs()
|
||||
}
|
||||
|
||||
func parseFile(filename string) (*Config, error) {
|
||||
|
||||
Reference in New Issue
Block a user