parseEnvFileFlag extracts the --env-file value from os.Args and CODER_DEV_ENV_FILE before serpent runs, so that loaded variables are visible to serpent's Env-tag resolution for other options.
()
| 467 | // CODER_DEV_ENV_FILE before serpent runs, so that loaded variables |
| 468 | // are visible to serpent's Env-tag resolution for other options. |
| 469 | func parseEnvFileFlag() (string, error) { |
| 470 | for i, arg := range os.Args[1:] { |
| 471 | if arg == "--env-file" { |
| 472 | if i+2 >= len(os.Args) { |
| 473 | return "", xerrors.New("--env-file requires a value") |
| 474 | } |
| 475 | return os.Args[i+2], nil |
| 476 | } |
| 477 | if v, ok := strings.CutPrefix(arg, "--env-file="); ok { |
| 478 | return v, nil |
| 479 | } |
| 480 | } |
| 481 | return os.Getenv("CODER_DEV_ENV_FILE"), nil |
| 482 | } |
| 483 | |
| 484 | // loadEnvFile reads the file at path using godotenv and sets any variables |
| 485 | // not already present in the process environment. It returns the number of |