From 4b09664903d6adf4e9415adcb1e182d8802daa0a Mon Sep 17 00:00:00 2001 From: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri, 30 Aug 2024 16:45:43 +0300 Subject: [PATCH] cmd: imp code --- internal/cmd/args.go | 2 +- internal/cmd/{flags.go => flag.go} | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) rename internal/cmd/{flags.go => flag.go} (80%) diff --git a/internal/cmd/args.go b/internal/cmd/args.go index d54f81985..447ee8430 100644 --- a/internal/cmd/args.go +++ b/internal/cmd/args.go @@ -441,7 +441,7 @@ func addOption(flags *flag.FlagSet, fieldPtr any, o *commandLineOption) { case *float32: defineFlagVar(flags, newFloat32Value(*fieldPtr, fieldPtr), o) case *[]int: - defineFlagVar(flags, newIntListValue(*fieldPtr, fieldPtr), o) + defineFlagVar(flags, newIntSliceValue(*fieldPtr, fieldPtr), o) case *[]string: defineFlagVar(flags, newStringsValue(*fieldPtr, fieldPtr), o) case encoding.TextUnmarshaler: diff --git a/internal/cmd/flags.go b/internal/cmd/flag.go similarity index 80% rename from internal/cmd/flags.go rename to internal/cmd/flag.go index 4648a7f65..6e8bf0018 100644 --- a/internal/cmd/flags.go +++ b/internal/cmd/flag.go @@ -59,29 +59,29 @@ func (i *float32Value) String() (out string) { return strconv.FormatFloat(float64(*i), 'f', 3, 32) } -// intListValue is a slice of integers that can be defined as a flag for +// intSliceValue is a slice of integers that can be defined as a flag for // [flag.FlagSet]. -type intListValue []int +type intSliceValue []int -// newIntListValue returns a pointer to intListValue with the given value. -func newIntListValue(val []int, p *[]int) (out *intListValue) { +// newIntSliceValue returns a pointer to intSliceValue with the given value. +func newIntSliceValue(val []int, p *[]int) (out *intSliceValue) { *p = val - return (*intListValue)(p) + return (*intSliceValue)(p) } // type check -var _ flag.Value = (*intListValue)(nil) +var _ flag.Value = (*intSliceValue)(nil) -// Set implements the [flag.Value] interface for *intListValue. -func (i *intListValue) Set(s string) (err error) { +// Set implements the [flag.Value] interface for *intSliceValue. +func (i *intSliceValue) Set(s string) (err error) { values := strings.Split(s, ",") var intVal int64 for _, v := range values { intVal, err = strconv.ParseInt(v, 0, 32) if err != nil { - return fmt.Errorf("parsing integer list arg %q: %w", s, err) + return fmt.Errorf("parsing integer slice arg %q: %w", s, err) } *i = append(*i, int(intVal)) @@ -90,8 +90,8 @@ func (i *intListValue) Set(s string) (err error) { return nil } -// String implements the [flag.Value] interface for *intListValue. -func (i *intListValue) String() (out string) { +// String implements the [flag.Value] interface for *intSliceValue. +func (i *intSliceValue) String() (out string) { for _, v := range *i { if len(out) > 0 { out += ","