update input/outpu

This commit is contained in:
2020-10-25 19:20:19 +03:00
parent 1c7e9623ce
commit 8886872c77
41 changed files with 660 additions and 613 deletions

View File

@@ -3,7 +3,7 @@ package value
import "gitoa.ru/go-4devs/console/input/flag"
type Any struct {
Empty
empty
Val []interface{}
Flag flag.Flag
}

View File

@@ -7,7 +7,7 @@ import (
)
type Bool struct {
Empty
empty
Val []bool
Flag flag.Flag
}

View File

@@ -7,7 +7,7 @@ import (
)
type Duration struct {
Empty
empty
Val []time.Duration
Flag flag.Flag
}

View File

@@ -4,84 +4,90 @@ import (
"time"
)
type Empty struct{}
var Empty = &empty{}
func (e *Empty) Append(string) error {
func IsEmpty(v Value) bool {
return v == Empty
}
type empty struct{}
func (e *empty) Append(string) error {
return ErrAppendEmpty
}
func (e *Empty) String() string {
func (e *empty) String() string {
return ""
}
func (e *Empty) Int() int {
func (e *empty) Int() int {
return 0
}
func (e *Empty) Int64() int64 {
func (e *empty) Int64() int64 {
return 0
}
func (e *Empty) Uint() uint {
func (e *empty) Uint() uint {
return 0
}
func (e *Empty) Uint64() uint64 {
func (e *empty) Uint64() uint64 {
return 0
}
func (e *Empty) Float64() float64 {
func (e *empty) Float64() float64 {
return 0
}
func (e *Empty) Bool() bool {
func (e *empty) Bool() bool {
return false
}
func (e *Empty) Duration() time.Duration {
func (e *empty) Duration() time.Duration {
return 0
}
func (e *Empty) Time() time.Time {
func (e *empty) Time() time.Time {
return time.Time{}
}
func (e *Empty) Strings() []string {
func (e *empty) Strings() []string {
return nil
}
func (e *Empty) Ints() []int {
func (e *empty) Ints() []int {
return nil
}
func (e *Empty) Int64s() []int64 {
func (e *empty) Int64s() []int64 {
return nil
}
func (e *Empty) Uints() []uint {
func (e *empty) Uints() []uint {
return nil
}
func (e *Empty) Uint64s() []uint64 {
func (e *empty) Uint64s() []uint64 {
return nil
}
func (e *Empty) Float64s() []float64 {
func (e *empty) Float64s() []float64 {
return nil
}
func (e *Empty) Bools() []bool {
func (e *empty) Bools() []bool {
return nil
}
func (e *Empty) Durations() []time.Duration {
func (e *empty) Durations() []time.Duration {
return nil
}
func (e *Empty) Times() []time.Time {
func (e *empty) Times() []time.Time {
return nil
}
func (e *Empty) Any() interface{} {
func (e *empty) Any() interface{} {
return nil
}

View File

@@ -7,7 +7,7 @@ import (
)
type Float64 struct {
Empty
empty
Val []float64
Flag flag.Flag
}

View File

@@ -7,7 +7,7 @@ import (
)
type Int struct {
Empty
empty
Val []int
Flag flag.Flag
}

View File

@@ -7,7 +7,7 @@ import (
)
type Int64 struct {
Empty
empty
Val []int64
Flag flag.Flag
}

View File

@@ -4,7 +4,7 @@ import (
"errors"
)
var _ AppendValue = (*Read)(nil)
var _ Append = (*Read)(nil)
var (
ErrAppendRead = errors.New("invalid append data to read value")

View File

@@ -3,7 +3,7 @@ package value
import "gitoa.ru/go-4devs/console/input/flag"
type String struct {
Empty
empty
Val []string
Flag flag.Flag
}

View File

@@ -7,7 +7,7 @@ import (
)
type Time struct {
Empty
empty
Val []time.Time
Flag flag.Flag
}

View File

@@ -7,7 +7,7 @@ import (
)
type Uint struct {
Empty
empty
Val []uint
Flag flag.Flag
}

View File

@@ -7,7 +7,7 @@ import (
)
type Uint64 struct {
Empty
empty
Val []uint64
Flag flag.Flag
}

View File

@@ -29,13 +29,13 @@ type Value interface {
Times() []time.Time
}
type AppendValue interface {
type Append interface {
Value
Append(string) error
}
//nolint: gocyclo
func New(v interface{}) Value {
func New(v interface{}) Append {
switch val := v.(type) {
case string:
return &String{Val: []string{val}, Flag: flag.String}
@@ -75,18 +75,20 @@ func New(v interface{}) Value {
return &Int{Val: val, Flag: flag.Int | flag.Array}
case []interface{}:
return &Any{Val: val, Flag: flag.Any | flag.Array}
case Value:
case Append:
return val
case Value:
return &Read{Value: val}
default:
if v != nil {
return &Any{Val: []interface{}{v}, Flag: flag.Any}
}
return &Empty{}
return &empty{}
}
}
func ByFlag(f flag.Flag) AppendValue {
func ByFlag(f flag.Flag) Append {
switch {
case f.IsInt():
return &Int{Flag: f | flag.Int}