Change name and prepare for push
This commit is contained in:
38
config.go
38
config.go
@@ -96,31 +96,46 @@ func defaultConfig() Config {
|
||||
}
|
||||
|
||||
func configPath() (string, error) {
|
||||
if path := os.Getenv("DIPLE_CONFIG"); path != "" {
|
||||
return path, nil
|
||||
}
|
||||
// Preserve the old override during the rename so existing scripts do not
|
||||
// silently start with a fresh configuration.
|
||||
if path := os.Getenv("GH_THREADS_CONFIG"); path != "" {
|
||||
return path, nil
|
||||
}
|
||||
if base := os.Getenv("XDG_CONFIG_HOME"); base != "" {
|
||||
return filepath.Join(base, "gh-threads", "config.toml"), nil
|
||||
return firstExistingOrDefault(
|
||||
filepath.Join(base, "diple", "config.toml"),
|
||||
filepath.Join(base, "gh-threads", "config.toml"),
|
||||
), nil
|
||||
}
|
||||
base, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("find user config directory: %w", err)
|
||||
}
|
||||
preferred := filepath.Join(base, "gh-threads", "config.toml")
|
||||
preferred := filepath.Join(base, "diple", "config.toml")
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("find home directory: %w", err)
|
||||
}
|
||||
fallback := filepath.Join(home, ".config", "gh-threads", "config.toml")
|
||||
return existingConfigPath(preferred, fallback), nil
|
||||
dotConfig := filepath.Join(home, ".config", "diple", "config.toml")
|
||||
legacyPreferred := filepath.Join(base, "gh-threads", "config.toml")
|
||||
legacyDotConfig := filepath.Join(home, ".config", "gh-threads", "config.toml")
|
||||
return firstExistingOrDefault(
|
||||
preferred, dotConfig, legacyPreferred, legacyDotConfig,
|
||||
), nil
|
||||
}
|
||||
|
||||
func existingConfigPath(preferred, fallback string) string {
|
||||
if _, err := os.Stat(preferred); err == nil || !errors.Is(err, os.ErrNotExist) {
|
||||
return preferred
|
||||
}
|
||||
if _, err := os.Stat(fallback); err == nil {
|
||||
return fallback
|
||||
return firstExistingOrDefault(preferred, fallback)
|
||||
}
|
||||
|
||||
func firstExistingOrDefault(preferred string, alternatives ...string) string {
|
||||
for _, candidate := range append([]string{preferred}, alternatives...) {
|
||||
if _, err := os.Stat(candidate); err == nil || !errors.Is(err, os.ErrNotExist) {
|
||||
return candidate
|
||||
}
|
||||
}
|
||||
return preferred
|
||||
}
|
||||
@@ -200,7 +215,10 @@ func defaultCacheDir() (string, error) {
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("find user cache directory: %w", err)
|
||||
}
|
||||
return filepath.Join(base, "gh-threads"), nil
|
||||
return firstExistingOrDefault(
|
||||
filepath.Join(base, "diple"),
|
||||
filepath.Join(base, "gh-threads"),
|
||||
), nil
|
||||
}
|
||||
|
||||
func validateThreadStatusOrder(order []string) error {
|
||||
|
||||
Reference in New Issue
Block a user