diff --git a/flags.go b/flags.go index c3c18f4..7e4e32d 100644 --- a/flags.go +++ b/flags.go @@ -11,13 +11,8 @@ import ( "github.com/urfave/cli/v3" ) -// -// -// - type NaturalTimeFlag = cli.FlagBase[nostr.Timestamp, struct{}, naturalTimeValue] -// wrap to satisfy flag interface. type naturalTimeValue struct { timestamp *nostr.Timestamp hasBeenSet bool @@ -25,8 +20,6 @@ type naturalTimeValue struct { var _ cli.ValueCreator[nostr.Timestamp, struct{}] = naturalTimeValue{} -// Below functions are to satisfy the ValueCreator interface - func (t naturalTimeValue) Create(val nostr.Timestamp, p *nostr.Timestamp, c struct{}) cli.Value { *p = val return &naturalTimeValue{ @@ -36,16 +29,12 @@ func (t naturalTimeValue) Create(val nostr.Timestamp, p *nostr.Timestamp, c stru func (t naturalTimeValue) ToString(b nostr.Timestamp) string { ts := b.Time() - if ts.IsZero() { return "" } return fmt.Sprintf("%v", ts) } -// Below functions are to satisfy the flag.Value interface - -// Parses the string value to timestamp func (t *naturalTimeValue) Set(value string) error { var ts time.Time if n, err := strconv.ParseInt(value, 10, 64); err == nil { @@ -74,20 +63,9 @@ func (t *naturalTimeValue) Set(value string) error { return nil } -// String returns a readable representation of this value (for usage defaults) -func (t *naturalTimeValue) String() string { - return fmt.Sprintf("%#v", t.timestamp) -} - -// Value returns the timestamp value stored in the flag -func (t *naturalTimeValue) Value() *nostr.Timestamp { - return t.timestamp -} - -// Get returns the flag structure -func (t *naturalTimeValue) Get() any { - return *t.timestamp -} +func (t *naturalTimeValue) String() string { return fmt.Sprintf("%#v", t.timestamp) } +func (t *naturalTimeValue) Value() *nostr.Timestamp { return t.timestamp } +func (t *naturalTimeValue) Get() any { return *t.timestamp } func getNaturalDate(cmd *cli.Command, name string) nostr.Timestamp { return cmd.Value(name).(nostr.Timestamp) @@ -101,7 +79,6 @@ type ( PubKeyFlag = cli.FlagBase[nostr.PubKey, struct{}, pubkeyValue] ) -// wrap to satisfy flag interface. type pubkeyValue struct { pubkey nostr.PubKey hasBeenSet bool @@ -109,8 +86,6 @@ type pubkeyValue struct { var _ cli.ValueCreator[nostr.PubKey, struct{}] = pubkeyValue{} -// Below functions are to satisfy the ValueCreator interface - func (t pubkeyValue) Create(val nostr.PubKey, p *nostr.PubKey, c struct{}) cli.Value { *p = val return &pubkeyValue{ @@ -118,13 +93,8 @@ func (t pubkeyValue) Create(val nostr.PubKey, p *nostr.PubKey, c struct{}) cli.V } } -func (t pubkeyValue) ToString(b nostr.PubKey) string { - return t.pubkey.String() -} +func (t pubkeyValue) ToString(b nostr.PubKey) string { return t.pubkey.String() } -// Below functions are to satisfy the flag.Value interface - -// Parses the string value to timestamp func (t *pubkeyValue) Set(value string) error { pk, err := nostr.PubKeyFromHex(value) t.pubkey = pk @@ -132,20 +102,9 @@ func (t *pubkeyValue) Set(value string) error { return err } -// String returns a readable representation of this value (for usage defaults) -func (t *pubkeyValue) String() string { - return fmt.Sprintf("%#v", t.pubkey) -} - -// Value returns the pubkey value stored in the flag -func (t *pubkeyValue) Value() nostr.PubKey { - return t.pubkey -} - -// Get returns the flag structure -func (t *pubkeyValue) Get() any { - return t.pubkey -} +func (t *pubkeyValue) String() string { return fmt.Sprintf("%#v", t.pubkey) } +func (t *pubkeyValue) Value() nostr.PubKey { return t.pubkey } +func (t *pubkeyValue) Get() any { return t.pubkey } func getPubKey(cmd *cli.Command, name string) nostr.PubKey { return cmd.Value(name).(nostr.PubKey) @@ -172,7 +131,6 @@ type ( IDFlag = cli.FlagBase[nostr.ID, struct{}, idValue] ) -// wrap to satisfy flag interface. type idValue struct { id nostr.ID hasBeenSet bool @@ -180,22 +138,14 @@ type idValue struct { var _ cli.ValueCreator[nostr.ID, struct{}] = idValue{} -// Below functions are to satisfy the ValueCreator interface - func (t idValue) Create(val nostr.ID, p *nostr.ID, c struct{}) cli.Value { *p = val return &idValue{ id: val, } } +func (t idValue) ToString(b nostr.ID) string { return t.id.String() } -func (t idValue) ToString(b nostr.ID) string { - return t.id.String() -} - -// Below functions are to satisfy the flag.Value interface - -// Parses the string value to timestamp func (t *idValue) Set(value string) error { pk, err := nostr.IDFromHex(value) t.id = pk @@ -203,20 +153,9 @@ func (t *idValue) Set(value string) error { return err } -// String returns a readable representation of this value (for usage defaults) -func (t *idValue) String() string { - return fmt.Sprintf("%#v", t.id) -} - -// Value returns the id value stored in the flag -func (t *idValue) Value() nostr.ID { - return t.id -} - -// Get returns the flag structure -func (t *idValue) Get() any { - return t.id -} +func (t *idValue) String() string { return fmt.Sprintf("%#v", t.id) } +func (t *idValue) Value() nostr.ID { return t.id } +func (t *idValue) Get() any { return t.id } func getID(cmd *cli.Command, name string) nostr.ID { return cmd.Value(name).(nostr.ID)