support config clone timeout, do upgrades

This commit is contained in:
2025-04-23 11:01:52 -04:00
parent d291489247
commit 5f0db640df
7 changed files with 178 additions and 148 deletions

View File

@ -1,6 +1,7 @@
package config
import (
"sync"
"time"
"gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/info"
@ -9,14 +10,17 @@ import (
type Config struct {
// Named keys above maintained for backwards compatibility
// Ideally only Gitlabs is used
Remotes []info.RemoteInfo
LogLevel string `yaml:"logLevel" json:"logLevel" enum:"info,warn,debug,error"`
ProjectPath string `yaml:"projectPath" json:"projectPath"`
Cache cacheConfig `yaml:"cache" json:"cache"`
Dump struct {
Full bool `yaml:"full" json:"full"`
Remotes []info.RemoteInfo `yaml:"remotes" json:"remotes,omitempty"`
LogLevel string `yaml:"logLevel" json:"logLevel,omitempty" enum:"info,warn,debug,error"`
ProjectPath string `yaml:"projectPath" json:"projectPath,omitempty"`
Cache cacheConfig `yaml:"cache" json:"cache"`
CloneTimeout string `yaml:"cloneTimeout" json:"cloneTimeout,omitempty" default:"120s"`
cloneTimeout time.Duration
Dump struct {
Full bool `yaml:"full" json:"full,omitempty"`
} `yaml:"dump" json:"dump"`
Editor editorConfig `yaml:"editor" json:"editor"`
lock *sync.RWMutex
}
type editorConfig struct {
@ -39,12 +43,13 @@ type cacheConfig struct {
} `yaml:"unlock" json:"unlock"`
Clear struct {
ClearAliases bool `yaml:"clearAliases,omitempty" json:"clearAliases,omitempty"`
} `yaml:"clear,omitempty" json:"clear,omitempty"`
} `yaml:"clear" json:"clear"`
}
var DefaultConfig = Config{
LogLevel: "warn",
ProjectPath: "~/work/projects",
LogLevel: "warn",
ProjectPath: "~/work/projects",
CloneTimeout: "120s",
Remotes: []info.RemoteInfo{{
Host: "https://gitlab.com",
Token: "yourtokenhere",
@ -59,3 +64,29 @@ var DefaultConfig = Config{
},
},
}
func NewConfig() *Config {
return &Config{
lock: &sync.RWMutex{},
}
}
// Perform updates to config
func (c *Config) Prepare() (err error) {
c.lock.Lock()
defer c.lock.Unlock()
if c.CloneTimeout == "" {
c.CloneTimeout = DefaultConfig.CloneTimeout
}
c.cloneTimeout, err = time.ParseDuration(c.CloneTimeout)
return err
}
func (c *Config) GetCloneTimeout() time.Duration {
c.lock.RLock()
defer c.lock.RUnlock()
return c.cloneTimeout
}