22 lines
468 B
Go
22 lines
468 B
Go
package middleman
|
|
|
|
import (
|
|
"github.com/urfave/cli/v3"
|
|
"strings"
|
|
)
|
|
|
|
func PluckEnvVar(prefix, flagName string, more ...string) cli.ValueSourceChain {
|
|
prefix = strings.ToUpper(strings.TrimSpace(prefix))
|
|
key := strings.ToUpper(strings.ReplaceAll(flagName, "-", "_"))
|
|
if prefix != "" {
|
|
key = prefix + "_" + key
|
|
}
|
|
n := len(more)
|
|
keys := make([]string, 0, n+1)
|
|
keys = append(keys, key)
|
|
if n > 0 {
|
|
keys = append(keys, more...)
|
|
}
|
|
return cli.EnvVars(keys...)
|
|
}
|