[#747] neofs-adm: Support ~
for paths in config
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
b5cadff2c3
commit
aa0955f15d
3 changed files with 26 additions and 2 deletions
24
cmd/neofs-adm/internal/modules/config/util.go
Normal file
24
cmd/neofs-adm/internal/modules/config/util.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ResolveHomePath replaces leading `~`
|
||||
// with home directory.
|
||||
//
|
||||
// Does nothing if path does not start
|
||||
// with contain `~`.
|
||||
func ResolveHomePath(path string) string {
|
||||
homeDir, _ := os.UserHomeDir()
|
||||
|
||||
if path == "~" {
|
||||
path = homeDir
|
||||
} else if strings.HasPrefix(path, "~/") {
|
||||
path = filepath.Join(homeDir, path[2:])
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue