Fix:(issue_1206) Default value shouldnt depend on env variable or value set from cmdline
This commit is contained in:
@@ -31,10 +31,10 @@ func (f *StringFlag) GetDefaultText() string {
|
||||
if f.DefaultText != "" {
|
||||
return f.DefaultText
|
||||
}
|
||||
if f.Value == "" {
|
||||
return f.Value
|
||||
if f.defaultValue == "" {
|
||||
return f.defaultValue
|
||||
}
|
||||
return fmt.Sprintf("%q", f.Value)
|
||||
return fmt.Sprintf("%q", f.defaultValue)
|
||||
}
|
||||
|
||||
// GetEnvVars returns the env vars for this flag
|
||||
@@ -44,6 +44,9 @@ func (f *StringFlag) GetEnvVars() []string {
|
||||
|
||||
// Apply populates the flag given the flag set and environment
|
||||
func (f *StringFlag) Apply(set *flag.FlagSet) error {
|
||||
// set default value so that environment wont be able to overwrite it
|
||||
f.defaultValue = f.Value
|
||||
|
||||
if val, _, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found {
|
||||
f.Value = val
|
||||
f.HasBeenSet = true
|
||||
|
Reference in New Issue
Block a user