remove cruft and comments from flags.go

This commit is contained in:
fiatjaf 2025-04-25 12:45:38 -03:00
parent 024111a8be
commit 148f6e8bcb
1 changed files with 11 additions and 72 deletions

View File

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