Skip to content

Commit

Permalink
feat: Help text should take into account terminal width
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Schmidt committed Jul 17, 2024
1 parent ffdbc88 commit b70fb94
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 69 deletions.
17 changes: 8 additions & 9 deletions cmd/flags/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log/slog"
"time"

commonFlags "github.com/aerospike/tools-common-go/flags"
"github.com/spf13/pflag"
)

Expand All @@ -30,14 +29,14 @@ func NewClientFlags() *ClientFlags {

func (cf *ClientFlags) NewClientFlagSet() *pflag.FlagSet {
flagSet := &pflag.FlagSet{}
flagSet.VarP(cf.Host, Host, "h", commonFlags.DefaultWrapHelpString(fmt.Sprintf("The AVS host to connect to. If cluster discovery is needed use --%s. Additionally can be set using the environment variable ASVEC_HOST.", Seeds))) //nolint:lll // For readability
flagSet.Var(cf.Seeds, Seeds, commonFlags.DefaultWrapHelpString(fmt.Sprintf("The AVS seeds to use for cluster discovery. If no cluster discovery is needed (i.e. load-balancer) then use --%s. Additionally can be set using the environment variable ASVEC_SEEDS.", Host))) //nolint:lll // For readability
flagSet.VarP(&cf.ListenerName, ListenerName, "l", commonFlags.DefaultWrapHelpString("The listener to ask the AVS server for as configured in the AVS server. Likely required for cloud deployments.")) //nolint:lll // For readability
flagSet.VarP(&cf.AuthCredentials.User, AuthUser, "U", commonFlags.DefaultWrapHelpString("The AVS user used to authenticate. Additionally can be set using the environment variable ASVEC_USER")) //nolint:lll // For readability
flagSet.VarP(&cf.AuthCredentials.Password, AuthPassword, "P", commonFlags.DefaultWrapHelpString("The AVS password for the specified user. If a password is not provided you will be prompted. Additionally can be set using the environment variable ASVEC_PASSWORD.")) //nolint:lll // For readability
flagSet.VarP(&cf.AuthCredentials, AuthCredentials, "C", commonFlags.DefaultWrapHelpString("The AVS user and password used to authenticate. Additionally can be set using the environment variable ASVEC_CREDENTIALS. If a password is not provided you will be prompted. This flag is provided in addition to --user and --password")) //nolint:lll // For readability
flagSet.DurationVar(&cf.Timeout, Timeout, time.Second*5, commonFlags.DefaultWrapHelpString("The timeout to use for each request to AVS")) //nolint:lll // For readability
flagSet.AddFlagSet(cf.NewTLSFlagSet(commonFlags.DefaultWrapHelpString))
flagSet.VarP(cf.Host, Host, "h", fmt.Sprintf("The AVS host to connect to. If cluster discovery is needed use --%s. Additionally can be set using the environment variable ASVEC_HOST.", Seeds)) //nolint:lll // For readability
flagSet.Var(cf.Seeds, Seeds, fmt.Sprintf("The AVS seeds to use for cluster discovery. If no cluster discovery is needed (i.e. load-balancer) then use --%s. Additionally can be set using the environment variable ASVEC_SEEDS.", Host)) //nolint:lll // For readability
flagSet.VarP(&cf.ListenerName, ListenerName, "l", "The listener to ask the AVS server for as configured in the AVS server. Likely required for cloud deployments.") //nolint:lll // For readability
flagSet.VarP(&cf.AuthCredentials.User, AuthUser, "U", "The AVS user used to authenticate. Additionally can be set using the environment variable ASVEC_USER") //nolint:lll // For readability
flagSet.VarP(&cf.AuthCredentials.Password, AuthPassword, "P", "The AVS password for the specified user. If a password is not provided you will be prompted. Additionally can be set using the environment variable ASVEC_PASSWORD.") //nolint:lll // For readability
flagSet.VarP(&cf.AuthCredentials, AuthCredentials, "C", "The AVS user and password used to authenticate. Additionally can be set using the environment variable ASVEC_CREDENTIALS. If a password is not provided you will be prompted. This flag is provided in addition to --user and --password") //nolint:lll // For readability
flagSet.DurationVar(&cf.Timeout, Timeout, time.Second*5, "The timeout to use for each request to AVS") //nolint:lll // For readability
flagSet.AddFlagSet(cf.NewTLSFlagSet(func(s string) string { return s }))

return flagSet
}
Expand Down
21 changes: 10 additions & 11 deletions cmd/flags/hnsw.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package flags
import (
"log/slog"

commonFlags "github.com/aerospike/tools-common-go/flags"
"github.com/spf13/pflag"
)

Expand All @@ -21,8 +20,8 @@ func NewHnswBatchingFlags() *BatchingFlags {

func (cf *BatchingFlags) NewFlagSet() *pflag.FlagSet {
flagSet := &pflag.FlagSet{}
flagSet.Var(&cf.MaxRecords, BatchMaxRecords, commonFlags.DefaultWrapHelpString("Maximum number of records to fit in a batch.")) //nolint:lll // For readability
flagSet.Var(&cf.Interval, BatchInterval, commonFlags.DefaultWrapHelpString("The maximum amount of time to wait before finalizing a batch.")) //nolint:lll // For readability
flagSet.Var(&cf.MaxRecords, BatchMaxRecords, "Maximum number of records to fit in a batch.") //nolint:lll // For readability
flagSet.Var(&cf.Interval, BatchInterval, "The maximum amount of time to wait before finalizing a batch.") //nolint:lll // For readability

return flagSet
}
Expand All @@ -48,8 +47,8 @@ func NewHnswCachingFlags() *CachingFlags {

func (cf *CachingFlags) NewFlagSet() *pflag.FlagSet {
flagSet := &pflag.FlagSet{}
flagSet.Var(&cf.MaxEntries, HnswCacheMaxEntries, commonFlags.DefaultWrapHelpString("Maximum number of entries to cache.")) //nolint:lll // For readability
flagSet.Var(&cf.Expiry, HnswCacheExpiry, commonFlags.DefaultWrapHelpString("A cache entry will expire after this amount of time has passed since the entry was added to cache")) //nolint:lll // For readability
flagSet.Var(&cf.MaxEntries, HnswCacheMaxEntries, "Maximum number of entries to cache.") //nolint:lll // For readability
flagSet.Var(&cf.Expiry, HnswCacheExpiry, "A cache entry will expire after this amount of time has passed since the entry was added to cache") //nolint:lll // For readability

return flagSet
}
Expand Down Expand Up @@ -81,11 +80,11 @@ func NewHnswHealerFlags() *HealerFlags {

func (cf *HealerFlags) NewFlagSet() *pflag.FlagSet {
flagSet := &pflag.FlagSet{}
flagSet.Var(&cf.MaxScanRatePerNode, HnswHealerMaxScanRatePerNode, commonFlags.DefaultWrapHelpString("Maximum allowed record scan rate per AVS node.")) //nolint:lll // For readability
flagSet.Var(&cf.MaxScanPageSize, HnswHealerMaxScanPageSize, commonFlags.DefaultWrapHelpString("Maximum number of records in a single scanned page.")) //nolint:lll // For readability
flagSet.Var(&cf.ReindexPercent, HnswHealerReindexPercent, commonFlags.DefaultWrapHelpString("Percentage of good records randomly selected for reindexing in a healer cycle.")) //nolint:lll // For readability
flagSet.Var(&cf.ScheduleDelay, HnswHealerScheduleDelay, commonFlags.DefaultWrapHelpString("The time delay between the termination of a healer run and the commencement of the next one for an index.")) //nolint:lll // For readability
flagSet.Var(&cf.Parallelism, HnswHealerParallelism, commonFlags.DefaultWrapHelpString("Maximum number of records to heal in parallel.")) //nolint:lll // For readability
flagSet.Var(&cf.MaxScanRatePerNode, HnswHealerMaxScanRatePerNode, "Maximum allowed record scan rate per AVS node.") //nolint:lll // For readability
flagSet.Var(&cf.MaxScanPageSize, HnswHealerMaxScanPageSize, "Maximum number of records in a single scanned page.") //nolint:lll // For readability
flagSet.Var(&cf.ReindexPercent, HnswHealerReindexPercent, "Percentage of good records randomly selected for reindexing in a healer cycle.") //nolint:lll // For readability
flagSet.Var(&cf.ScheduleDelay, HnswHealerScheduleDelay, "The time delay between the termination of a healer run and the commencement of the next one for an index.") //nolint:lll // For readability
flagSet.Var(&cf.Parallelism, HnswHealerParallelism, "Maximum number of records to heal in parallel.") //nolint:lll // For readability

return flagSet
}
Expand All @@ -112,7 +111,7 @@ func NewHnswMergeFlags() *MergeFlags {

func (cf *MergeFlags) NewFlagSet() *pflag.FlagSet {
flagSet := &pflag.FlagSet{}
flagSet.Var(&cf.Parallelism, HnswMergeParallelism, commonFlags.DefaultWrapHelpString("The number of vectors merged in parallel from a batch index to main index.")) //nolint:lll // For readability
flagSet.Var(&cf.Parallelism, HnswMergeParallelism, "The number of vectors merged in parallel from a batch index to main index.") //nolint:lll // For readability

return flagSet
}
Expand Down
Loading

0 comments on commit b70fb94

Please sign in to comment.