mirror of
https://github.com/therootcompany/golib.git
synced 2026-11-04 06:55:00 +00:00
fix: rename envfile flag to env-file with backwards compatibility
This commit is contained in:
parent
71671b7852
commit
6a1e49f20a
@ -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 {
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user