diff --git a/flag.go b/flag.go index 6754863050..e4357f3f3c 100644 --- a/flag.go +++ b/flag.go @@ -378,17 +378,17 @@ func hasFlag(flags []Flag, fl Flag) bool { // Return the first value from a list of environment variables and files // (which may or may not exist), a description of where the value was found, // and a boolean which is true if a value was found. -func flagFromEnvOrFile(envVars []string, filePath string) (value string, fromWhere string, found bool) { +func flagFromEnvOrFile(envVars []string, filePaths []string) (value string, fromWhere string, found bool) { for _, envVar := range envVars { envVar = strings.TrimSpace(envVar) if value, found := syscall.Getenv(envVar); found { return value, fmt.Sprintf("environment variable %q", envVar), true } } - for _, fileVar := range strings.Split(filePath, ",") { + for _, fileVar := range filePaths { if fileVar != "" { if data, err := os.ReadFile(fileVar); err == nil { - return string(data), fmt.Sprintf("file %q", filePath), true + return string(data), fmt.Sprintf("file %q", filePaths), true } } } diff --git a/flag_impl.go b/flag_impl.go index cd3d3a5e14..18566fa86c 100644 --- a/flag_impl.go +++ b/flag_impl.go @@ -36,10 +36,10 @@ type NoConfig struct{} type FlagBase[T any, C any, VC ValueCreator[T, C]] struct { Name string // name of the flag - Category string // category of the flag, if any - DefaultText string // default text of the flag for usage purposes - FilePath string // file path to load value from - Usage string // usage string for help output + Category string // category of the flag, if any + DefaultText string // default text of the flag for usage purposes + FilePaths []string // file paths to load value from + Usage string // usage string for help output Required bool // whether the flag is required or not Hidden bool // whether to hide the flag in help output @@ -84,7 +84,7 @@ func (f *FlagBase[T, C, V]) Apply(set *flag.FlagSet) error { if !f.applied || !f.Persistent { newVal := f.Value - if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { + if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePaths); found { tmpVal := f.creator.Create(f.Value, new(T), f.Config) if val != "" || reflect.TypeOf(f.Value).Kind() == reflect.String { if err := tmpVal.Set(val); err != nil { diff --git a/flag_test.go b/flag_test.go index 95e3bd9348..9bee920d67 100644 --- a/flag_test.go +++ b/flag_test.go @@ -2565,7 +2565,7 @@ func TestFlagFromFile(t *testing.T) { } for _, filePathTest := range filePathTests { - got, _, _ := flagFromEnvOrFile(filePathTest.name, filePathTest.path) + got, _, _ := flagFromEnvOrFile(filePathTest.name, []string{filePathTest.path}) if want := filePathTest.expected; got != want { t.Errorf("Did not expect %v - Want %v", got, want) } diff --git a/godoc-current.txt b/godoc-current.txt index 4f426b7ace..6e3aca2877 100644 --- a/godoc-current.txt +++ b/godoc-current.txt @@ -775,10 +775,10 @@ var VersionFlag Flag = &BoolFlag{ type FlagBase[T any, C any, VC ValueCreator[T, C]] struct { Name string // name of the flag - Category string // category of the flag, if any - DefaultText string // default text of the flag for usage purposes - FilePath string // file path to load value from - Usage string // usage string for help output + Category string // category of the flag, if any + DefaultText string // default text of the flag for usage purposes + FilePaths []string // file paths to load value from + Usage string // usage string for help output Required bool // whether the flag is required or not Hidden bool // whether to hide the flag in help output diff --git a/testdata/godoc-v3.x.txt b/testdata/godoc-v3.x.txt index 4f426b7ace..6e3aca2877 100644 --- a/testdata/godoc-v3.x.txt +++ b/testdata/godoc-v3.x.txt @@ -775,10 +775,10 @@ var VersionFlag Flag = &BoolFlag{ type FlagBase[T any, C any, VC ValueCreator[T, C]] struct { Name string // name of the flag - Category string // category of the flag, if any - DefaultText string // default text of the flag for usage purposes - FilePath string // file path to load value from - Usage string // usage string for help output + Category string // category of the flag, if any + DefaultText string // default text of the flag for usage purposes + FilePaths []string // file paths to load value from + Usage string // usage string for help output Required bool // whether the flag is required or not Hidden bool // whether to hide the flag in help output