Refactor code style for improved readability and consistency.
This commit is contained in:
1 parent
463c013056
commit
94bfc87e9d
4 files changed
+118
-156
No files matched your search
+23
-31
@@ -29,10 +29,10 @@ const (
|
||||
|
||||
// Defaults for keys that may be omitted.
|
||||
const (
|
||||
DefaultInterval = 3 * time.Minute
|
||||
DefaultInterval = 3 * time.Minute
|
||||
DefaultCooldown = 30 * time.Minute
|
||||
DefaultSandboxTimeout = 2 * time.Second
|
||||
DefaultSessionTimeout = 5 * time.Minute
|
||||
DefaultSandboxTimeout = 2 * time.Second
|
||||
DefaultSessionTimeout = 5 * time.Minute
|
||||
DefaultMemoryMB = 64
|
||||
DefaultCallStack = 200
|
||||
)
|
||||
@@ -130,9 +130,7 @@ type Options struct {
|
||||
// DefaultPath returns dibs.toml in the user config dir.
|
||||
func DefaultPath() (string, error) {
|
||||
dir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err != nil { return "", err }
|
||||
return filepath.Join(dir, "dibs", "dibs.toml"), nil
|
||||
}
|
||||
|
||||
@@ -140,22 +138,18 @@ func DefaultPath() (string, error) {
|
||||
// are returned together as Errors.
|
||||
func Load(path string, opts Options) (*Config, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err != nil { return nil, err }
|
||||
|
||||
abs, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err != nil { return nil, err }
|
||||
|
||||
if opts.LookupEnv == nil {
|
||||
opts.LookupEnv = os.LookupEnv
|
||||
}
|
||||
|
||||
cfg := &Config{
|
||||
Path: abs,
|
||||
Notify: Notify{
|
||||
Path: abs,
|
||||
Notify: Notify{
|
||||
Desktop: true,
|
||||
Cooldown: Duration{Duration: DefaultCooldown},
|
||||
},
|
||||
@@ -177,27 +171,25 @@ func Load(path string, opts Options) (*Config, error) {
|
||||
var decErr *toml.DecodeError
|
||||
|
||||
switch {
|
||||
case err == nil:
|
||||
case errors.As(err, &strict):
|
||||
// The rest of the document was decoded, so keep validating it.
|
||||
for _, e := range strict.Errors {
|
||||
msg := "unknown key"
|
||||
if k := e.Key(); len(k) > 0 && k[len(k)-1] == "quantity" {
|
||||
msg = "unknown key: quantity is always 1 and cannot be configured"
|
||||
case err == nil:
|
||||
case errors.As(err, &strict):
|
||||
// The rest of the document was decoded, so keep validating it.
|
||||
for _, e := range strict.Errors {
|
||||
msg := "unknown key"
|
||||
if k := e.Key(); len(k) > 0 && k[len(k)-1] == "quantity" {
|
||||
msg = "unknown key: quantity is always 1 and cannot be configured"
|
||||
}
|
||||
v.decodeError(&e, msg)
|
||||
}
|
||||
v.decodeError(&e, msg)
|
||||
}
|
||||
case errors.As(err, &decErr):
|
||||
v.decodeError(decErr, "")
|
||||
return nil, v.errs
|
||||
default:
|
||||
return nil, err
|
||||
case errors.As(err, &decErr):
|
||||
v.decodeError(decErr, "")
|
||||
return nil, v.errs
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
|
||||
v.validate(cfg, opts)
|
||||
if len(v.errs) > 0 {
|
||||
return nil, v.errs
|
||||
}
|
||||
if len(v.errs) > 0 { return nil, v.errs }
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
Reference in new issue
Block a user