MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / ExpandHomePath

Function ExpandHomePath

internal/config/config.go:1377–1412  ·  view source on GitHub ↗

ExpandHomePath expands a leading ~ in paths using the current user's home directory.

(path string)

Source from the content-addressed store, hash-verified

1375
1376// ExpandHomePath expands a leading ~ in paths using the current user's home directory.
1377func ExpandHomePath(path string) string {
1378 trimmed := strings.TrimSpace(path)
1379 if trimmed == "" {
1380 return trimmed
1381 }
1382
1383 if trimmed == "~" {
1384 home, err := os.UserHomeDir()
1385 if err != nil {
1386 return trimmed
1387 }
1388 return home
1389 }
1390
1391 if strings.HasPrefix(trimmed, "~/") || strings.HasPrefix(trimmed, "~\\") {
1392 home, err := os.UserHomeDir()
1393 if err != nil {
1394 return trimmed
1395 }
1396 rest := strings.TrimPrefix(trimmed, "~")
1397 rest = strings.TrimPrefix(rest, "/")
1398 rest = strings.TrimPrefix(rest, "\\")
1399 return filepath.Join(home, rest)
1400 }
1401
1402 if strings.HasPrefix(trimmed, "~"+string(os.PathSeparator)) {
1403 home, err := os.UserHomeDir()
1404 if err != nil {
1405 return trimmed
1406 }
1407 rest := strings.TrimPrefix(trimmed, "~"+string(os.PathSeparator))
1408 return filepath.Join(home, rest)
1409 }
1410
1411 return trimmed
1412}
1413
1414func parseEnvPort(name string) int {
1415 raw := strings.TrimSpace(os.Getenv(name))

Callers 10

NewConfigWizardPageFunction · 0.92
BootstrapFunction · 0.92
applyFlagsToConfigFunction · 0.92
TestExpandHomePathFunction · 0.85
NewConfigFunction · 0.85
MergeWithFileMethod · 0.85
SetDefaultsMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestExpandHomePathFunction · 0.68