diff --git a/app_helpers.go b/app_helpers.go index 0ee58b5..863b210 100644 --- a/app_helpers.go +++ b/app_helpers.go @@ -5,119 +5,119 @@ import ( "strings" ) -// validateCommands checks if a command is valid and initialize it -func validateCommands(commands []Cmd) ([]Cmd, error) { - var cmds []Cmd +// It checks if a list of commands and initialize them if they are valid. +func validateCommands(commands []Cmd) (cmds []Cmd, err error) { for _, c := range commands { name := strings.TrimSpace(c.Name) if name == "" { - return nil, fmt.Errorf("command name has empty value") + err = fmt.Errorf("one command name has empty value") + return } - vflags, err := validateFlagsAndInit(c.Flags) - if err != nil { - return nil, err + flags, errf := validateFlagsAndInit(c.Flags) + if errf != nil { + err = errf + return } - c.Flags = vflags + c.Flags = flags cmds = append(cmds, c) } - return cmds, nil + return } -// validateFlagsAndInit validates flags and initialize them -func validateFlagsAndInit(flags []Flag) ([]Flag, error) { - var vFlags []Flag +// It checks a list of flags and initialize them if they are valid. +func validateFlagsAndInit(flags []Flag) (vflags []Flag, err error) { for _, v := range flags { switch f := v.(type) { case FlagBool: - name := strings.ToLower(strings.TrimSpace(f.Name)) - if name == "" { - return nil, fmt.Errorf("flag name has empty value") + if name := strings.ToLower(strings.TrimSpace(f.Name)); name == "" { + err = fmt.Errorf("bool flag name has an empty value") + return } f.initialize() - vFlags = append(vFlags, f) + vflags = append(vflags, f) + case FlagInt: - name := strings.ToLower(strings.TrimSpace(f.Name)) - if name == "" { - return nil, fmt.Errorf("flag name has empty value") + if name := strings.ToLower(strings.TrimSpace(f.Name)); name == "" { + err = fmt.Errorf("int flag name has an empty value") + return } f.initialize() - vFlags = append(vFlags, f) + vflags = append(vflags, f) + case FlagString: - name := strings.ToLower(strings.TrimSpace(f.Name)) - if name == "" { - return nil, fmt.Errorf("flag name has empty value") + if name := strings.ToLower(strings.TrimSpace(f.Name)); name == "" { + err = fmt.Errorf("string flag name has an empty value") + return } f.initialize() - vFlags = append(vFlags, f) + vflags = append(vflags, f) + case FlagStringSlice: - name := strings.ToLower(strings.TrimSpace(f.Name)) - if name == "" { - return nil, fmt.Errorf("flag name has empty value") + if name := strings.ToLower(strings.TrimSpace(f.Name)); name == "" { + err = fmt.Errorf("string slice flag name has an empty value") + return } f.initialize() - vFlags = append(vFlags, f) + vflags = append(vflags, f) + default: - return nil, fmt.Errorf("flag has invalid data type value. Use bool, int, string, []string or nil") + err = fmt.Errorf("one flag has invalid data type value. Use a bool, int, string, []string or nil value") + return } } - return vFlags, nil + return } -// findFlagByKey finds a flag item with its index in a flag's array by key. -// It also checks if was a short flag or not. +// It finds a flag item with its index in a given flags array by key +// then checks if every flag is a short flag or not. func findFlagByKey(key string, flags []Flag) (int, Flag, bool) { - var short bool = false for i, v := range flags { switch f := v.(type) { case FlagBool: // Check for long named flags - if key == f.Name { - return i, f, short + if f.Name == key { + return i, f, false } // Check for short named flags for _, s := range f.Aliases { - if key == s { - short = true - return i, f, short + if s == key { + return i, f, true } } case FlagInt: // Check for long named flags - if key == f.Name { - return i, f, short + if f.Name == key { + return i, f, false } // Check for short named flags for _, s := range f.Aliases { - if key == s { - short = true - return i, f, short + if s == key { + return i, f, true } } case FlagString: // Check for long named flags - if key == f.Name { - return i, f, short + if f.Name == key { + return i, f, false } // Check for short named flags for _, s := range f.Aliases { - if key == s { - short = true - return i, f, short + if s == key { + return i, f, true } } case FlagStringSlice: // Check for long named flags - if key == f.Name { - return i, f, short + if f.Name == key { + return i, f, false } // Check for short named flags for _, s := range f.Aliases { - if key == s { - short = true - return i, f, short + if s == key { + return i, f, true } } } } - return -1, nil, short + return -1, nil, false } diff --git a/flag_types.go b/flag_types.go index 377242b..65f9120 100644 --- a/flag_types.go +++ b/flag_types.go @@ -6,20 +6,30 @@ import ( "syscall" ) -// FlagInt defines a flag with `Int` type. +// FlagInt defines an `Int` type flag. type FlagInt struct { - Name string - Summary string - Value int - Aliases []string - EnvVar string + // Name of the flag containing alphanumeric characters and dashes + // but without leading dashes, spaces or any kind of special chars. + Name string + // An optional summary for the flag. + Summary string + // An optional default value for the flag. + Value int + // An optional list of flag aliases containing single alphanumeric characters + // but without dashes, spaces or any special chars. + Aliases []string + // An optional environment variable containing uppercase alphanumeric characters + // and underscores but without dashes, spaces or any kind of special chars. + EnvVar string + flagValue AnyValue flagAssigned bool flagProvided bool flagProvidedAsAlias bool } -// initialize sets a default flag value via associated `Value` prop or an environment variable (`EnvVar`). +// It sets a default flag value via its associated `Value` prop +// or its environment variable (`EnvVar`) if so. func (fi *FlagInt) initialize() { val := AnyValue(strconv.Itoa(fi.Value)) ev, ok := syscall.Getenv(fi.EnvVar) @@ -32,20 +42,30 @@ func (fi *FlagInt) initialize() { fi.flagValue = val } -// FlagBool defines a flag with `bool` type. +// FlagBool defines a `bool` type flag. type FlagBool struct { - Name string - Summary string - Value bool - Aliases []string - EnvVar string + // Name of the flag containing alphanumeric characters and dashes + // but without leading dashes, spaces or any kind of special chars. + Name string + // An optional summary for the flag. + Summary string + // An optional default value for the flag. + Value bool + // An optional list of flag aliases containing single alphanumeric characters + // but without dashes, spaces or any special chars. + Aliases []string + // An optional environment variable containing uppercase alphanumeric characters + // and underscores but without dashes, spaces or any kind of special chars. + EnvVar string + flagValue AnyValue flagAssigned bool flagProvided bool flagProvidedAsAlias bool } -// initialize sets a default flag value via associated `Value` prop or an environment variable (`EnvVar`). +// It sets a default flag value via its associated `Value` prop +// or its environment variable (`EnvVar`) if so. func (fb *FlagBool) initialize() { val := AnyValue(strconv.FormatBool(fb.Value)) ev, ok := syscall.Getenv(fb.EnvVar) @@ -57,20 +77,30 @@ func (fb *FlagBool) initialize() { fb.flagValue = val } -// FlagString defines a flag with `String` type. +// FlagString defines a `String` type flag. type FlagString struct { - Name string - Summary string - Value string - Aliases []string - EnvVar string + // Name of the flag containing alphanumeric characters and dashes + // but without leading dashes, spaces or any kind of special chars. + Name string + // An optional summary for the flag. + Summary string + // An optional default value for the flag. + Value string + // An optional list of flag aliases containing single alphanumeric characters + // but without dashes, spaces or any special chars. + Aliases []string + // An optional environment variable containing uppercase alphanumeric characters + // and underscores but without dashes, spaces or any kind of special chars. + EnvVar string + flagValue AnyValue flagAssigned bool flagProvided bool flagProvidedAsAlias bool } -// initialize sets a default flag value via associated `Value` prop or an environment variable (`EnvVar`). +// It sets a default flag value via its associated `Value` prop +// or its environment variable (`EnvVar`) if so. func (fs *FlagString) initialize() { val := AnyValue(fs.Value) ev, ok := syscall.Getenv(fs.EnvVar) @@ -80,20 +110,30 @@ func (fs *FlagString) initialize() { fs.flagValue = val } -// FlagStringSlice defines a flag with string slice type. +// FlagStringSlice defines a string slice type flag. type FlagStringSlice struct { - Name string - Summary string - Value []string - Aliases []string - EnvVar string + // Name of the flag containing alphanumeric characters and dashes + // but without leading dashes, spaces or any kind of special chars. + Name string + // An optional default value for the flag. + Summary string + // An optional default value for the flag. + Value []string + // An optional list of flag aliases containing single alphanumeric characters + // but without dashes, spaces or any special chars. + Aliases []string + // An optional environment variable containing uppercase alphanumeric characters + // and underscores but without dashes, spaces or any kind of special chars. + EnvVar string + flagValue AnyValue flagAssigned bool flagProvided bool flagProvidedAsAlias bool } -// initialize sets a default flag value via associated `Value` prop or an environment variable (`EnvVar`). +// It sets a default flag value via its associated `Value` prop +// or its environment variable (`EnvVar`) if so. func (fs *FlagStringSlice) initialize() { val := AnyValue(strings.Join(fs.Value, ",")) ev, ok := syscall.Getenv(fs.EnvVar) diff --git a/flag_values.go b/flag_values.go index 40c2f3f..e5cd6a2 100644 --- a/flag_values.go +++ b/flag_values.go @@ -2,25 +2,25 @@ package cline import ( "fmt" - "os" "strconv" "strings" ) -// AnyValue is an alias of string type which represents an input value for a command flag. +// AnyValue is an string type alias which represents +// an input value for a command flag. type AnyValue string -// ToBool converts current flag value into a `bool`. +// ToBool converts current flag value into `bool`. func (v AnyValue) ToBool() (bool, error) { return strconv.ParseBool(v.ToString()) } -// ToInt converts current flag value into an `int`. +// ToInt converts current flag value into `int`. func (v AnyValue) ToInt() (int, error) { return strconv.Atoi(v.ToString()) } -// ToString converts current flag value into a `string`. +// ToString converts current flag value into `string`. func (v AnyValue) ToString() string { return string(v) } @@ -34,27 +34,27 @@ func (v AnyValue) ToStringSlice() []string { return strs } -// FlagBoolValue represents a flag value bool type. +// FlagBoolValue represents a `bool` type flag value. type FlagBoolValue struct { flag FlagBool } -// Value unwraps the plain bool value of the current flag. +// Value unwraps the plain `bool` value of the current flag. func (v *FlagBoolValue) Value() (bool, error) { return v.flag.flagValue.ToBool() } -// IsProvided checks if current bool flag was provided from stdin. +// IsProvided checks if current `bool` flag was provided from stdin. func (v *FlagBoolValue) IsProvided() bool { return v.flag.flagProvided } -// IsProvidedShort checks if current bool flag was provided from stdin but using its short name. +// IsProvidedShort checks if current `bool` flag was provided from stdin but using its short name. func (v *FlagBoolValue) IsProvidedShort() bool { return v.flag.flagProvided && v.flag.flagProvidedAsAlias } -// IsProvidedLong checks if current bool flag was provided from stdin but using its long name. +// IsProvidedLong checks if current `bool` flag was provided from stdin but using its long name. func (v *FlagBoolValue) IsProvidedLong() bool { return v.flag.flagProvided && !v.flag.flagProvidedAsAlias } @@ -64,27 +64,27 @@ func (v *FlagBoolValue) GetFlagType() FlagBool { return v.flag } -// FlagIntValue represents a flag value int type. +// FlagIntValue represents an `int` type flag value. type FlagIntValue struct { flag FlagInt } -// Value unwraps the plain int value of the current flag. +// Value unwraps the plain `int` value of the current flag. func (v *FlagIntValue) Value() (int, error) { return v.flag.flagValue.ToInt() } -// IsProvided checks if current int flag was provided from stdin. +// IsProvided checks if current `int` flag was provided from stdin. func (v *FlagIntValue) IsProvided() bool { return v.flag.flagProvided } -// IsProvidedShort checks if current int flag was provided from stdin but using its short name. +// IsProvidedShort checks if current `int` flag was provided from stdin but using its short name. func (v *FlagIntValue) IsProvidedShort() bool { return v.flag.flagProvided && v.flag.flagProvidedAsAlias } -// IsProvidedLong checks if current int flag was provided from stdin but using its long name. +// IsProvidedLong checks if current `int` flag was provided from stdin but using its long name. func (v *FlagIntValue) IsProvidedLong() bool { return v.flag.flagProvided && !v.flag.flagProvidedAsAlias } @@ -94,27 +94,27 @@ func (v *FlagIntValue) GetFlagType() FlagInt { return v.flag } -// FlagStringValue represents a flag value string type. +// FlagStringValue represents a `string` type flag value. type FlagStringValue struct { flag FlagString } -// Value unwraps the plain string value of the current flag. +// Value unwraps the plain `string` value of the current flag. func (v *FlagStringValue) Value() string { return v.flag.flagValue.ToString() } -// IsProvided checks if current string flag was provided from stdin. +// IsProvided checks if current `string` flag was provided from stdin. func (v *FlagStringValue) IsProvided() bool { return v.flag.flagProvided } -// IsProvidedShort checks if current string flag was provided from stdin but using its short name. +// IsProvidedShort checks if current `string` flag was provided from stdin but using its short name. func (v *FlagStringValue) IsProvidedShort() bool { return v.flag.flagProvided && v.flag.flagProvidedAsAlias } -// IsProvidedLong checks if current string flag was provided from stdin but using its long name. +// IsProvidedLong checks if current `string` flag was provided from stdin but using its long name. func (v *FlagStringValue) IsProvidedLong() bool { return v.flag.flagProvided && !v.flag.flagProvidedAsAlias } @@ -124,7 +124,7 @@ func (v *FlagStringValue) GetFlagType() FlagString { return v.flag } -// FlagStringSliceValue represents a flag value string slice type. +// FlagStringSliceValue represents a string slice type flag value. type FlagStringSliceValue struct { flag FlagStringSlice } @@ -159,36 +159,39 @@ type FlagValues struct { flags []Flag } -// findByKey finds a `Flag` by its string key. -func (v *FlagValues) findByKey(longFlagName string) Flag { - for _, f := range v.flags { - switch fl := f.(type) { +// It finds a `Flag` by its string key in the inner list. +func (v *FlagValues) findByKey(longFlagName string) (flag Flag) { + for _, fl := range v.flags { + switch f := fl.(type) { case FlagBool: - if longFlagName == fl.Name { - return fl + if f.Name == longFlagName { + flag = f + return } case FlagInt: - if longFlagName == fl.Name { - return fl + if f.Name == longFlagName { + flag = f + return } case FlagString: - if longFlagName == fl.Name { - return fl + if f.Name == longFlagName { + flag = f + return } case FlagStringSlice: - if longFlagName == fl.Name { - return fl + if f.Name == longFlagName { + flag = f + return } } } - return nil + return } -// getProvidedFlags returns provided flags by specified filters. -func (v *FlagValues) getProvidedFlags(providedOnly bool, aliasOnly bool) []Flag { - var flags []Flag - for _, e := range v.flags { - switch f := e.(type) { +// It returns provided flags by specified filters. +func (v *FlagValues) getProvidedFlags(providedOnly bool, aliasOnly bool) (flags []Flag) { + for _, fl := range v.flags { + switch f := fl.(type) { case FlagBool: if !f.flagProvided { continue @@ -251,7 +254,7 @@ func (v *FlagValues) getProvidedFlags(providedOnly bool, aliasOnly bool) []Flag } } } - return flags + return } // GetProvided returns all flags that were provided from stdin only. @@ -269,8 +272,10 @@ func (v *FlagValues) GetProvidedShort() []Flag { return v.getProvidedFlags(false, true) } -// Any finds a flag value but ignoring its type. The result value is convertible to other supported types. -// Since `AnyValue` is just a `string` alias type, it can be converted easily with `string(AnyValue)`. +// Any gets the current flag value but ignoring its type. +// However, the resulted value is convertible into other supported types. +// And since the `AnyValue` is just an alias of built-in `string` type +// it can be easily converted too into string like `string(AnyValue)`. func (v *FlagValues) Any(longFlagName string) AnyValue { switch f := v.findByKey(longFlagName).(type) { case FlagBool: @@ -285,54 +290,71 @@ func (v *FlagValues) Any(longFlagName string) AnyValue { return AnyValue("") } -// Bool finds a `bool` flag value. It's type should match with its flag definition type. +// Bool gets a `bool` flag value which value type should match +// with its flag definition type, otherwise it just panics. func (v *FlagValues) Bool(longFlagName string) *FlagBoolValue { switch f := v.findByKey(longFlagName).(type) { case FlagBool: return &FlagBoolValue{flag: f} default: t := strings.ReplaceAll(fmt.Sprintf("%T", f), "cline.", "") - fmt.Printf("error: flag `--%s` value used as `FlagBoolValue` but declared as `%s`.\n", longFlagName, t) - os.Exit(1) + panic( + fmt.Sprintf( + "error: flag `--%s` value used as `FlagBoolValue` but declared as `%s`.\n", + longFlagName, + t), + ) } - return nil } -// Int finds a `int` flag value. It's type should match with its flag definition type. +// Int finds a `int` flag value which value type should match +// with its flag definition type, otherwise it just panics. func (v *FlagValues) Int(longFlagName string) *FlagIntValue { switch f := v.findByKey(longFlagName).(type) { case FlagInt: return &FlagIntValue{flag: f} default: t := strings.ReplaceAll(fmt.Sprintf("%T", f), "cline.", "") - fmt.Printf("error: flag `--%s` value used as `FlagIntValue` but declared as `%s`.\n", longFlagName, t) - os.Exit(1) + panic( + fmt.Sprintf( + "error: flag `--%s` value used as `FlagIntValue` but declared as `%s`.\n", + longFlagName, + t, + ), + ) } - return nil } -// String finds a `string` flag value. It's type should match with its flag definition type. +// String finds a `string` flag value which value type should match +// with its flag definition type, otherwise it just panics. func (v *FlagValues) String(longFlagName string) *FlagStringValue { switch f := v.findByKey(longFlagName).(type) { case FlagString: return &FlagStringValue{flag: f} default: t := strings.ReplaceAll(fmt.Sprintf("%T", f), "cline.", "") - fmt.Printf("error: flag `--%s` value used as `FlagStringValue` but declared as `%s`.\n", longFlagName, t) - os.Exit(1) + panic(fmt.Sprintf( + "error: flag `--%s` value used as `FlagStringValue` but declared as `%s`.\n", + longFlagName, + t, + )) } - return nil } -// StringSlice finds a string slice. It's type should match with its flag definition type. +// StringSlice finds a string slice which value type should match +// with its flag definition type, otherwise it just panics. func (v *FlagValues) StringSlice(longFlagName string) *FlagStringSliceValue { switch f := v.findByKey(longFlagName).(type) { case FlagStringSlice: return &FlagStringSliceValue{flag: f} default: t := strings.ReplaceAll(fmt.Sprintf("%T", f), "cline.", "") - fmt.Printf("error: flag `--%s` value used as `FlagStringSliceValue` but declared as `%s`.\n", longFlagName, t) - os.Exit(1) + panic( + fmt.Sprintf( + "error: flag `--%s` value used as `FlagStringSliceValue` but declared as `%s`.\n", + longFlagName, + t, + ), + ) } - return nil } diff --git a/flag_values_test.go b/flag_values_test.go new file mode 100644 index 0000000..5062cc7 --- /dev/null +++ b/flag_values_test.go @@ -0,0 +1,696 @@ +package cline + +import ( + "reflect" + "testing" +) + +func TestAnyValue_ToBool(t *testing.T) { + tests := []struct { + name string + v AnyValue + want bool + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := tt.v.ToBool() + if (err != nil) != tt.wantErr { + t.Errorf("AnyValue.ToBool() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("AnyValue.ToBool() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestAnyValue_ToInt(t *testing.T) { + tests := []struct { + name string + v AnyValue + want int + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := tt.v.ToInt() + if (err != nil) != tt.wantErr { + t.Errorf("AnyValue.ToInt() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("AnyValue.ToInt() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestAnyValue_ToString(t *testing.T) { + tests := []struct { + name string + v AnyValue + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := tt.v.ToString(); got != tt.want { + t.Errorf("AnyValue.ToString() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestAnyValue_ToStringSlice(t *testing.T) { + tests := []struct { + name string + v AnyValue + want []string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := tt.v.ToStringSlice(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("AnyValue.ToStringSlice() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagBoolValue_Value(t *testing.T) { + type fields struct { + flag FlagBool + } + tests := []struct { + name string + fields fields + want bool + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagBoolValue{ + flag: tt.fields.flag, + } + got, err := v.Value() + if (err != nil) != tt.wantErr { + t.Errorf("FlagBoolValue.Value() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("FlagBoolValue.Value() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagBoolValue_IsProvided(t *testing.T) { + type fields struct { + flag FlagBool + } + tests := []struct { + name string + fields fields + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagBoolValue{ + flag: tt.fields.flag, + } + if got := v.IsProvided(); got != tt.want { + t.Errorf("FlagBoolValue.IsProvided() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagBoolValue_IsProvidedShort(t *testing.T) { + type fields struct { + flag FlagBool + } + tests := []struct { + name string + fields fields + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagBoolValue{ + flag: tt.fields.flag, + } + if got := v.IsProvidedShort(); got != tt.want { + t.Errorf("FlagBoolValue.IsProvidedShort() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagBoolValue_IsProvidedLong(t *testing.T) { + type fields struct { + flag FlagBool + } + tests := []struct { + name string + fields fields + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagBoolValue{ + flag: tt.fields.flag, + } + if got := v.IsProvidedLong(); got != tt.want { + t.Errorf("FlagBoolValue.IsProvidedLong() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagBoolValue_GetFlagType(t *testing.T) { + type fields struct { + flag FlagBool + } + tests := []struct { + name string + fields fields + want FlagBool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagBoolValue{ + flag: tt.fields.flag, + } + if got := v.GetFlagType(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("FlagBoolValue.GetFlagType() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagStringValue_Value(t *testing.T) { + type fields struct { + flag FlagString + } + tests := []struct { + name string + fields fields + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagStringValue{ + flag: tt.fields.flag, + } + if got := v.Value(); got != tt.want { + t.Errorf("FlagStringValue.Value() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagStringValue_IsProvided(t *testing.T) { + type fields struct { + flag FlagString + } + tests := []struct { + name string + fields fields + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagStringValue{ + flag: tt.fields.flag, + } + if got := v.IsProvided(); got != tt.want { + t.Errorf("FlagStringValue.IsProvided() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagStringValue_IsProvidedShort(t *testing.T) { + type fields struct { + flag FlagString + } + tests := []struct { + name string + fields fields + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagStringValue{ + flag: tt.fields.flag, + } + if got := v.IsProvidedShort(); got != tt.want { + t.Errorf("FlagStringValue.IsProvidedShort() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagStringValue_IsProvidedLong(t *testing.T) { + type fields struct { + flag FlagString + } + tests := []struct { + name string + fields fields + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagStringValue{ + flag: tt.fields.flag, + } + if got := v.IsProvidedLong(); got != tt.want { + t.Errorf("FlagStringValue.IsProvidedLong() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagStringValue_GetFlagType(t *testing.T) { + type fields struct { + flag FlagString + } + tests := []struct { + name string + fields fields + want FlagString + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagStringValue{ + flag: tt.fields.flag, + } + if got := v.GetFlagType(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("FlagStringValue.GetFlagType() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagStringSliceValue_Value(t *testing.T) { + type fields struct { + flag FlagStringSlice + } + tests := []struct { + name string + fields fields + want []string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagStringSliceValue{ + flag: tt.fields.flag, + } + if got := v.Value(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("FlagStringSliceValue.Value() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagStringSliceValue_IsProvided(t *testing.T) { + type fields struct { + flag FlagStringSlice + } + tests := []struct { + name string + fields fields + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagStringSliceValue{ + flag: tt.fields.flag, + } + if got := v.IsProvided(); got != tt.want { + t.Errorf("FlagStringSliceValue.IsProvided() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagStringSliceValue_IsProvidedShort(t *testing.T) { + type fields struct { + flag FlagStringSlice + } + tests := []struct { + name string + fields fields + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagStringSliceValue{ + flag: tt.fields.flag, + } + if got := v.IsProvidedShort(); got != tt.want { + t.Errorf("FlagStringSliceValue.IsProvidedShort() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagStringSliceValue_IsProvidedLong(t *testing.T) { + type fields struct { + flag FlagStringSlice + } + tests := []struct { + name string + fields fields + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagStringSliceValue{ + flag: tt.fields.flag, + } + if got := v.IsProvidedLong(); got != tt.want { + t.Errorf("FlagStringSliceValue.IsProvidedLong() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagStringSliceValue_GetFlagType(t *testing.T) { + type fields struct { + flag FlagStringSlice + } + tests := []struct { + name string + fields fields + want FlagStringSlice + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagStringSliceValue{ + flag: tt.fields.flag, + } + if got := v.GetFlagType(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("FlagStringSliceValue.GetFlagType() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagValues_findByKey(t *testing.T) { + type fields struct { + flags []Flag + } + type args struct { + longFlagName string + } + tests := []struct { + name string + fields fields + args args + wantFlag Flag + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagValues{ + flags: tt.fields.flags, + } + if gotFlag := v.findByKey(tt.args.longFlagName); !reflect.DeepEqual(gotFlag, tt.wantFlag) { + t.Errorf("FlagValues.findByKey() = %v, want %v", gotFlag, tt.wantFlag) + } + }) + } +} + +func TestFlagValues_getProvidedFlags(t *testing.T) { + type fields struct { + flags []Flag + } + type args struct { + providedOnly bool + aliasOnly bool + } + tests := []struct { + name string + fields fields + args args + wantFlags []Flag + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagValues{ + flags: tt.fields.flags, + } + if gotFlags := v.getProvidedFlags(tt.args.providedOnly, tt.args.aliasOnly); !reflect.DeepEqual(gotFlags, tt.wantFlags) { + t.Errorf("FlagValues.getProvidedFlags() = %v, want %v", gotFlags, tt.wantFlags) + } + }) + } +} + +func TestFlagValues_GetProvided(t *testing.T) { + type fields struct { + flags []Flag + } + tests := []struct { + name string + fields fields + want []Flag + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagValues{ + flags: tt.fields.flags, + } + if got := v.GetProvided(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("FlagValues.GetProvided() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagValues_GetProvidedLong(t *testing.T) { + type fields struct { + flags []Flag + } + tests := []struct { + name string + fields fields + want []Flag + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagValues{ + flags: tt.fields.flags, + } + if got := v.GetProvidedLong(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("FlagValues.GetProvidedLong() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagValues_GetProvidedShort(t *testing.T) { + type fields struct { + flags []Flag + } + tests := []struct { + name string + fields fields + want []Flag + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagValues{ + flags: tt.fields.flags, + } + if got := v.GetProvidedShort(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("FlagValues.GetProvidedShort() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagValues_Any(t *testing.T) { + type fields struct { + flags []Flag + } + type args struct { + longFlagName string + } + tests := []struct { + name string + fields fields + args args + want AnyValue + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagValues{ + flags: tt.fields.flags, + } + if got := v.Any(tt.args.longFlagName); got != tt.want { + t.Errorf("FlagValues.Any() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagValues_Bool(t *testing.T) { + type fields struct { + flags []Flag + } + type args struct { + longFlagName string + } + tests := []struct { + name string + fields fields + args args + want *FlagBoolValue + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagValues{ + flags: tt.fields.flags, + } + if got := v.Bool(tt.args.longFlagName); !reflect.DeepEqual(got, tt.want) { + t.Errorf("FlagValues.Bool() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagValues_Int(t *testing.T) { + type fields struct { + flags []Flag + } + type args struct { + longFlagName string + } + tests := []struct { + name string + fields fields + args args + want *FlagIntValue + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagValues{ + flags: tt.fields.flags, + } + if got := v.Int(tt.args.longFlagName); !reflect.DeepEqual(got, tt.want) { + t.Errorf("FlagValues.Int() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagValues_String(t *testing.T) { + type fields struct { + flags []Flag + } + type args struct { + longFlagName string + } + tests := []struct { + name string + fields fields + args args + want *FlagStringValue + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagValues{ + flags: tt.fields.flags, + } + if got := v.String(tt.args.longFlagName); !reflect.DeepEqual(got, tt.want) { + t.Errorf("FlagValues.String() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestFlagValues_StringSlice(t *testing.T) { + type fields struct { + flags []Flag + } + type args struct { + longFlagName string + } + tests := []struct { + name string + fields fields + args args + want *FlagStringSliceValue + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &FlagValues{ + flags: tt.fields.flags, + } + if got := v.StringSlice(tt.args.longFlagName); !reflect.DeepEqual(got, tt.want) { + t.Errorf("FlagValues.StringSlice() = %v, want %v", got, tt.want) + } + }) + } +}