Remove legacy config path handling
This commit is contained in:
@@ -29,8 +29,6 @@ mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/docspell-cli"
|
||||
cp docspell-cli-example.json "${XDG_CONFIG_HOME:-$HOME/.config}/docspell-cli/config.json"
|
||||
```
|
||||
|
||||
For compatibility, the legacy `~/docspell-cli.json` file is still read if the XDG config file does not exist, but the tool will print a warning asking you to move it.
|
||||
|
||||
```json
|
||||
{
|
||||
"passwordCommand": "pass",
|
||||
|
||||
@@ -120,7 +120,7 @@ func newCLIParser() (*flaggy.Parser, cliCommands) {
|
||||
}
|
||||
|
||||
func loadConfigAndPassword() (config, string) {
|
||||
configFile, legacyTarget, err := configFilePath()
|
||||
configFile, err := configFilePath()
|
||||
if err != nil {
|
||||
fmt.Println("Error finding config directory:", err)
|
||||
os.Exit(1)
|
||||
@@ -130,9 +130,6 @@ func loadConfigAndPassword() (config, string) {
|
||||
fmt.Printf("Error reading config file %s: %v\n", configFile, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if legacyTarget != "" {
|
||||
fmt.Fprintf(os.Stderr, "Warning: using legacy config file %s; move it to %s\n", configFile, legacyTarget)
|
||||
}
|
||||
|
||||
var cfg config
|
||||
if err := json.Unmarshal(configData, &cfg); err != nil {
|
||||
@@ -150,27 +147,12 @@ func loadConfigAndPassword() (config, string) {
|
||||
return cfg, strings.TrimSpace(string(password))
|
||||
}
|
||||
|
||||
func configFilePath() (path string, legacyTarget string, err error) {
|
||||
func configFilePath() (string, error) {
|
||||
configDir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return "", err
|
||||
}
|
||||
xdgPath := filepath.Join(configDir, "docspell-cli", "config.json")
|
||||
if _, err := os.Stat(xdgPath); err == nil {
|
||||
return xdgPath, "", nil
|
||||
} else if !os.IsNotExist(err) {
|
||||
return xdgPath, "", nil
|
||||
}
|
||||
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return xdgPath, "", nil
|
||||
}
|
||||
legacyPath := filepath.Join(homeDir, "docspell-cli.json")
|
||||
if _, err := os.Stat(legacyPath); err == nil {
|
||||
return legacyPath, xdgPath, nil
|
||||
}
|
||||
return xdgPath, "", nil
|
||||
return filepath.Join(configDir, "docspell-cli", "config.json"), nil
|
||||
}
|
||||
|
||||
func runImportCommand(cfg config, password string, args []string) {
|
||||
|
||||
+1
-27
@@ -10,7 +10,7 @@ func TestConfigFilePathUsesXDGConfigDir(t *testing.T) {
|
||||
t.Setenv("HOME", t.TempDir())
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
|
||||
got, legacy, err := configFilePath()
|
||||
got, err := configFilePath()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -18,30 +18,4 @@ func TestConfigFilePathUsesXDGConfigDir(t *testing.T) {
|
||||
if got != want {
|
||||
t.Fatalf("expected %q, got %q", want, got)
|
||||
}
|
||||
if legacy != "" {
|
||||
t.Fatalf("expected no legacy fallback, got %q", legacy)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigFilePathFallsBackToLegacyHomeFile(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
xdg := filepath.Join(t.TempDir(), "config")
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("XDG_CONFIG_HOME", xdg)
|
||||
legacyPath := filepath.Join(home, "docspell-cli.json")
|
||||
if err := os.WriteFile(legacyPath, []byte("{}"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
got, legacy, err := configFilePath()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != legacyPath {
|
||||
t.Fatalf("expected legacy path %q, got %q", legacyPath, got)
|
||||
}
|
||||
wantLegacy := filepath.Join(xdg, "docspell-cli", "config.json")
|
||||
if legacy != wantLegacy {
|
||||
t.Fatalf("expected XDG target %q, got %q", wantLegacy, legacy)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user