* WIP on auto-generating CLi * WIP * WIP * WIP * add pagination.go * handle more flag types * WIP on refactoring * WIP * working tests * add docs * echo all flags * add repeated tests * remove comment * fix compositeListValue issue Co-authored-by: Anil Kumar Kammari <anil@vitwit.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
52 lines
963 B
Go
52 lines
963 B
Go
package flag
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/spf13/pflag"
|
|
"google.golang.org/protobuf/reflect/protoreflect"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
)
|
|
|
|
type timestampType struct{}
|
|
|
|
func (t timestampType) NewValue(context.Context, *Builder) pflag.Value {
|
|
return ×tampValue{}
|
|
}
|
|
|
|
func (t timestampType) DefaultValue() string {
|
|
return ""
|
|
}
|
|
|
|
type timestampValue struct {
|
|
value *timestamppb.Timestamp
|
|
}
|
|
|
|
func (t timestampValue) Get() protoreflect.Value {
|
|
if t.value == nil {
|
|
return protoreflect.Value{}
|
|
}
|
|
return protoreflect.ValueOfMessage(t.value.ProtoReflect())
|
|
}
|
|
|
|
func (v timestampValue) String() string {
|
|
if v.value == nil {
|
|
return ""
|
|
}
|
|
return v.value.AsTime().Format(time.RFC3339)
|
|
}
|
|
|
|
func (v *timestampValue) Set(s string) error {
|
|
t, err := time.Parse(time.RFC3339, s)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
v.value = timestamppb.New(t)
|
|
return nil
|
|
}
|
|
|
|
func (v timestampValue) Type() string {
|
|
return "timestamp (RFC 3339)"
|
|
}
|