github.com/vipernet-xyz/tm@v0.34.24/tools/tm-signer-harness/internal/utils.go (about)

     1  package internal
     2  
     3  import (
     4  	"os/user"
     5  	"path/filepath"
     6  	"strings"
     7  )
     8  
     9  // ExpandPath will check if the given path begins with a "~" symbol, and if so,
    10  // will expand it to become the user's home directory. If it fails to expand the
    11  // path it will automatically return the original path itself.
    12  func ExpandPath(path string) string {
    13  	usr, err := user.Current()
    14  	if err != nil {
    15  		return path
    16  	}
    17  
    18  	if path == "~" {
    19  		return usr.HomeDir
    20  	} else if strings.HasPrefix(path, "~/") {
    21  		return filepath.Join(usr.HomeDir, path[2:])
    22  	}
    23  
    24  	return path
    25  }