Skip to content

Commit

Permalink
Add error checks
Browse files Browse the repository at this point in the history
  • Loading branch information
skelouse committed Oct 7, 2023
1 parent d7bd472 commit 72f7639
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 79 deletions.
60 changes: 45 additions & 15 deletions altsrc/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ func (f *GenericFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceCo
continue
}
for _, n := range f.Names() {
_ = f.set.Set(n, value.String())
if err := f.set.Set(n, value.String()); err != nil {
return err
}
}
}

Expand Down Expand Up @@ -109,10 +111,14 @@ func (f *StringSliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSour
continue
}
underlyingFlag.Value = &sliceValue
_ = f.set.Set(n, sliceValue.Serialize())
if err := f.set.Set(n, sliceValue.Serialize()); err != nil {
return err
}
}
if f.Destination != nil {
_ = f.Destination.Set(sliceValue.Serialize())
if err := f.Destination.Set(sliceValue.Serialize()); err != nil {
return err
}
}
}
return nil
Expand Down Expand Up @@ -143,7 +149,9 @@ func (f *IntSliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceC
underlyingFlag.Value = &sliceValue
}
if f.Destination != nil {
_ = f.Destination.Set(sliceValue.Serialize())
if err := f.Destination.Set(sliceValue.Serialize()); err != nil {
return err
}
}
}
return nil
Expand Down Expand Up @@ -174,7 +182,9 @@ func (f *Int64SliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourc
underlyingFlag.Value = &sliceValue
}
if f.Destination != nil {
_ = f.Destination.Set(sliceValue.Serialize())
if err := f.Destination.Set(sliceValue.Serialize()); err != nil {
return err
}
}
}
return nil
Expand Down Expand Up @@ -205,7 +215,9 @@ func (f *Float64SliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSou
underlyingFlag.Value = &sliceValue
}
if f.Destination != nil {
_ = f.Destination.Set(sliceValue.Serialize())
if err := f.Destination.Set(sliceValue.Serialize()); err != nil {
return err
}
}
}
return nil
Expand All @@ -225,7 +237,9 @@ func (f *BoolFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceConte
return err
}
for _, n := range f.Names() {
_ = f.set.Set(n, strconv.FormatBool(value))
if err := f.set.Set(n, strconv.FormatBool(value)); err != nil {
return err
}
}
}
return nil
Expand All @@ -245,7 +259,9 @@ func (f *StringFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceCon
return err
}
for _, n := range f.Names() {
_ = f.set.Set(n, value)
if err := f.set.Set(n, value); err != nil {
return err
}
}
}
return nil
Expand Down Expand Up @@ -275,7 +291,9 @@ func (f *PathFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceConte
}
value = filepath.Join(filepath.Dir(basePathAbs), value)
}
_ = f.set.Set(n, value)
if err := f.set.Set(n, value); err != nil {
return err
}
}
}
return nil
Expand All @@ -295,7 +313,9 @@ func (f *IntFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContex
return err
}
for _, n := range f.Names() {
_ = f.set.Set(n, strconv.FormatInt(int64(value), 10))
if err := f.set.Set(n, strconv.FormatInt(int64(value), 10)); err != nil {
return err
}
}
}
return nil
Expand All @@ -314,7 +334,9 @@ func (f *Int64Flag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceCont
return err
}
for _, n := range f.Names() {
_ = f.set.Set(n, strconv.FormatInt(value, 10))
if err := f.set.Set(n, strconv.FormatInt(value, 10)); err != nil {
return err
}
}
}
return nil
Expand All @@ -333,7 +355,9 @@ func (f *UintFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceConte
return err
}
for _, n := range f.Names() {
_ = f.set.Set(n, strconv.FormatUint(uint64(value), 10))
if err := f.set.Set(n, strconv.FormatUint(uint64(value), 10)); err != nil {
return err
}
}
}
return nil
Expand All @@ -352,7 +376,9 @@ func (f *Uint64Flag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceCon
return err
}
for _, n := range f.Names() {
_ = f.set.Set(n, strconv.FormatUint(value, 10))
if err := f.set.Set(n, strconv.FormatUint(value, 10)); err != nil {
return err
}
}
}
return nil
Expand All @@ -372,7 +398,9 @@ func (f *DurationFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceC
return err
}
for _, n := range f.Names() {
_ = f.set.Set(n, value.String())
if err := f.set.Set(n, value.String()); err != nil {
return err
}
}
}
return nil
Expand All @@ -393,7 +421,9 @@ func (f *Float64Flag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceCo
}
floatStr := float64ToString(value)
for _, n := range f.Names() {
_ = f.set.Set(n, floatStr)
if err := f.set.Set(n, floatStr); err != nil {
return err
}
}
}
return nil
Expand Down
Loading

0 comments on commit 72f7639

Please sign in to comment.