From 6a1e49f20a22159f49fe6a69a03abb45fcae2c8e Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 13 Aug 2026 14:59:47 -0600 Subject: [PATCH] fix: rename envfile flag to env-file with backwards compatibility --- cmd/auth-proxy/main.go | 7 ++++--- cmd/sendsms/main.go | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/cmd/auth-proxy/main.go b/cmd/auth-proxy/main.go index fd8ccc7..1dc8a41 100644 --- a/cmd/auth-proxy/main.go +++ b/cmd/auth-proxy/main.go @@ -108,8 +108,8 @@ func main() { QueryParamNames: nil, // []string{"access_token", "token"}, } - // Peek for --envfile early - envPath := peekOption(os.Args[1:], []string{"-envfile", "--envfile"}, ".env") + // Peek for --env-file early + envPath := peekOption(os.Args[1:], []string{"-env-file", "--env-file", "-envfile", "--envfile"}, ".env") _ = godotenv.Load(envPath) // silent if missing // Override defaults from env @@ -608,7 +608,8 @@ func (cli *MainConfig) authenticate(r *http.Request) (auth.BasicPrinciple, error return cred, err } -// peekOption looks for a flag value without parsing the full set +// peekOption looks for a flag value without parsing the full set. +// Used to handle --env-file before flag.Parse so it doesn't conflict with other flags. func peekOption(args []string, names []string, def string) string { for i := range len(args) { for _, name := range names { diff --git a/cmd/sendsms/main.go b/cmd/sendsms/main.go index 682a8f9..6dd904f 100644 --- a/cmd/sendsms/main.go +++ b/cmd/sendsms/main.go @@ -78,7 +78,8 @@ func main() { maxDelay: 2 * time.Minute, } - _ = godotenv.Load("./.env") + envPath := peekOption(os.Args[1:], []string{"-env-file", "--env-file", "-envfile", "--envfile"}, ".env") + _ = godotenv.Load(envPath) // note: we could also use twilio, or whatever var sender SMSSender = androidsmsgateway.New( @@ -104,6 +105,9 @@ func main() { now := time.Now() zoneName, offset := now.Zone() + // --env-file is loaded via peekOption above; flag registered here for help output. + _ = flag.String("env-file", ".env", "path to .env file (default: .env in current directory)") + flag.BoolVar(&cfg.confirmed, "y", false, "Confirm without prompting") flag.BoolVar(&cfg.verbose, "verbose", false, "Show parse warnings and other debug info") flag.BoolVar(&cfg.dryRun, "dry-run", false, "Skip sending messages and sleeping, runs without confirmation") @@ -620,3 +624,18 @@ func parseClock(s string, ref time.Time) (t time.Time, err error) { t = time.Date(ref.Year(), ref.Month(), ref.Day(), hour, min, 0, 0, ref.Location()) return t, nil } + +// peekOption looks for a flag value without parsing the full set. +// Used to handle --env-file before flag.Parse so it doesn't conflict with other flags. +func peekOption(args []string, names []string, def string) string { + for i := range len(args) { + for _, name := range names { + if args[i] == name { + if i+1 < len(args) { + return args[i+1] + } + } + } + } + return def +}