From 17ec84151b4f9f3d2ff593ecdad41b8c0c860e02 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 5 Nov 2024 16:15:59 +0300 Subject: [PATCH] [#532] cli: Respect XDG base directory spec XDG base directory specification defines where various files should be looked by an application. Hopefully, this makes `frostfs-cli` more predictable and pleasant to work with. Luckily for us, golang already has everything we need in the stdlib. This commit also gets rid of `github.com/mitchellh/go-homedir` dependency. Close #532 Refs #1455 Signed-off-by: Evgenii Stratonikov --- cmd/frostfs-cli/modules/root.go | 11 +++++------ go.mod | 1 - go.sum | Bin 42276 -> 42095 bytes 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/cmd/frostfs-cli/modules/root.go b/cmd/frostfs-cli/modules/root.go index c0282586a..88acab341 100644 --- a/cmd/frostfs-cli/modules/root.go +++ b/cmd/frostfs-cli/modules/root.go @@ -21,7 +21,6 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/misc" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/config" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/gendoc" - "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -112,13 +111,13 @@ func initConfig() { // Use config file from the flag. viper.SetConfigFile(cfgFile) } else { - // Find home directory. - home, err := homedir.Dir() + // Find config directory. + configDir, err := os.UserConfigDir() if err != nil { - common.PrintVerbose(rootCmd, "Get homedir: %s", err) + common.PrintVerbose(rootCmd, "Get config dir: %s", err) } else { - // Search config in `$HOME/.config/frostfs-cli/` with name "config.yaml" - viper.AddConfigPath(filepath.Join(home, ".config", "frostfs-cli")) + // Search config in `$XDG_CONFIG_HOME/frostfs-cli/` with name "config.yaml" + viper.AddConfigPath(filepath.Join(configDir, "frostfs-cli")) viper.SetConfigName("config") viper.SetConfigType("yaml") } diff --git a/go.mod b/go.mod index ba9ec375c..886fa958f 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,6 @@ require ( github.com/hashicorp/golang-lru/v2 v2.0.7 github.com/klauspost/compress v1.17.4 github.com/mailru/easyjson v0.7.7 - github.com/mitchellh/go-homedir v1.1.0 github.com/mr-tron/base58 v1.2.0 github.com/multiformats/go-multiaddr v0.12.1 github.com/nspcc-dev/neo-go v0.106.3 diff --git a/go.sum b/go.sum index a037a99afb2f1123c99b416fc3c8486d5733d022..6ed130cdbed78cd7e7ea79de7fdbf0a971d8d274 100644 GIT binary patch delta 18 acmZ2-is}6crVacqlVx3nH(z)0O#lE+#Rsqe delta 158 zcmaEVf@#SqrVacq_UZY$8Tq-XDVaqIWrli&dIky^hE_SH*>09qnGtRkE^YzYj)rB$ zMW$5+$%YZ70WNv^6~X6 tmXl`U85)`CVwn~YVd7|7?p2iSQ{`D@=x11HP*7wrInYIGvyzK%0szd+H0A&R -- 2.45.2