From b70fb941e5fccdd281d7ddb3f46f3321afa688c5 Mon Sep 17 00:00:00 2001 From: Jesse Schmidt Date: Wed, 17 Jul 2024 12:28:42 -0700 Subject: [PATCH] feat: Help text should take into account terminal width --- cmd/flags/client.go | 17 ++++++++--------- cmd/flags/hnsw.go | 21 ++++++++++----------- cmd/indexCreate.go | 29 ++++++++++++++--------------- cmd/indexDrop.go | 9 ++++----- cmd/indexGC.go | 7 +++---- cmd/indexList.go | 3 +-- cmd/indexUpdate.go | 11 +++++------ cmd/root.go | 18 ++++++++++++++++-- cmd/userCreate.go | 7 +++---- cmd/userDrop.go | 3 +-- cmd/userGrant.go | 5 ++--- cmd/userNewPassword.go | 5 ++--- cmd/userRevoke.go | 5 ++--- 13 files changed, 71 insertions(+), 69 deletions(-) diff --git a/cmd/flags/client.go b/cmd/flags/client.go index e1e4dab..d17b062 100644 --- a/cmd/flags/client.go +++ b/cmd/flags/client.go @@ -5,7 +5,6 @@ import ( "log/slog" "time" - commonFlags "github.com/aerospike/tools-common-go/flags" "github.com/spf13/pflag" ) @@ -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 } diff --git a/cmd/flags/hnsw.go b/cmd/flags/hnsw.go index 2fe0efc..2a3ae75 100644 --- a/cmd/flags/hnsw.go +++ b/cmd/flags/hnsw.go @@ -3,7 +3,6 @@ package flags import ( "log/slog" - commonFlags "github.com/aerospike/tools-common-go/flags" "github.com/spf13/pflag" ) @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/cmd/indexCreate.go b/cmd/indexCreate.go index 0120220..e5267f2 100644 --- a/cmd/indexCreate.go +++ b/cmd/indexCreate.go @@ -9,7 +9,6 @@ import ( avs "github.com/aerospike/avs-client-go" "github.com/aerospike/avs-client-go/protos" - commonFlags "github.com/aerospike/tools-common-go/flags" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -51,20 +50,20 @@ var indexCreateFlags = &struct { func newIndexCreateFlagSet() *pflag.FlagSet { flagSet := &pflag.FlagSet{} - flagSet.BoolVarP(&indexCreateFlags.yes, flags.Yes, "y", false, commonFlags.DefaultWrapHelpString("When true do not prompt for confirmation.")) //nolint:lll // For readability - flagSet.StringVarP(&indexCreateFlags.namespace, flags.Namespace, "n", "", commonFlags.DefaultWrapHelpString("The namespace for the index.")) //nolint:lll // For readability - flagSet.StringSliceVarP(&indexCreateFlags.sets, flags.Sets, "s", nil, commonFlags.DefaultWrapHelpString("The sets for the index.")) //nolint:lll // For readability - flagSet.StringVarP(&indexCreateFlags.indexName, flags.IndexName, "i", "", commonFlags.DefaultWrapHelpString("The name of the index.")) //nolint:lll // For readability - flagSet.StringVarP(&indexCreateFlags.vectorField, flags.VectorField, "f", "", commonFlags.DefaultWrapHelpString("The name of the vector field.")) //nolint:lll // For readability - flagSet.Uint32VarP(&indexCreateFlags.dimensions, flags.Dimension, "d", 0, commonFlags.DefaultWrapHelpString("The dimension of the vector field.")) //nolint:lll // For readability - flagSet.VarP(&indexCreateFlags.distanceMetric, flags.DistanceMetric, "m", commonFlags.DefaultWrapHelpString(fmt.Sprintf("The distance metric for the index. Valid values: %s", strings.Join(flags.DistanceMetricEnum(), ", ")))) //nolint:lll // For readability - flagSet.StringToStringVar(&indexCreateFlags.indexLabels, flags.IndexLabels, nil, commonFlags.DefaultWrapHelpString("Optional labels to assign to the index. Example: \"model=all-MiniLM-L6-v2,foo=bar\"")) //nolint:lll // For readability //nolint:lll // For readability - flagSet.Var(&indexCreateFlags.storageNamespace, flags.StorageNamespace, commonFlags.DefaultWrapHelpString("Optional storage namespace where the index is stored. Defaults to the index namespace.")) //nolint:lll // For readability //nolint:lll // For readability - flagSet.Var(&indexCreateFlags.storageSet, flags.StorageSet, commonFlags.DefaultWrapHelpString("Optional storage set where the index is stored. Defaults to the index name.")) //nolint:lll // For readability //nolint:lll // For readability - flagSet.Var(&indexCreateFlags.hnswMaxEdges, flags.MaxEdges, commonFlags.DefaultWrapHelpString("Maximum number bi-directional links per HNSW vertex. Greater values of 'm' in general provide better recall for data with high dimensionality, while lower values work well for data with lower dimensionality. The storage space required for the index increases proportionally with 'm'.")) //nolint:lll // For readability - flagSet.Var(&indexCreateFlags.hnswConstructionEf, flags.ConstructionEf, commonFlags.DefaultWrapHelpString("The number of candidate nearest neighbors shortlisted during index creation. Larger values provide better recall at the cost of longer index update times. The default is 100.")) //nolint:lll // For readability - flagSet.Var(&indexCreateFlags.hnswEf, flags.Ef, commonFlags.DefaultWrapHelpString("The default number of candidate nearest neighbors shortlisted during search. Larger values provide better recall at the cost of longer search times. The default is 100.")) //nolint:lll // For readability - flagSet.Var(&indexCreateFlags.hnswMaxMemQueueSize, flags.HnswMaxMemQueueSize, commonFlags.DefaultWrapHelpString("Maximum size of in-memory queue for inserted/updated vector records.")) //nolint:lll // For readability //nolint:lll // For readability + flagSet.BoolVarP(&indexCreateFlags.yes, flags.Yes, "y", false, "When true do not prompt for confirmation.") //nolint:lll // For readability + flagSet.StringVarP(&indexCreateFlags.namespace, flags.Namespace, "n", "", "The namespace for the index.") //nolint:lll // For readability + flagSet.StringSliceVarP(&indexCreateFlags.sets, flags.Sets, "s", nil, "The sets for the index.") //nolint:lll // For readability + flagSet.StringVarP(&indexCreateFlags.indexName, flags.IndexName, "i", "", "The name of the index.") //nolint:lll // For readability + flagSet.StringVarP(&indexCreateFlags.vectorField, flags.VectorField, "f", "", "The name of the vector field.") //nolint:lll // For readability + flagSet.Uint32VarP(&indexCreateFlags.dimensions, flags.Dimension, "d", 0, "The dimension of the vector field.") //nolint:lll // For readability + flagSet.VarP(&indexCreateFlags.distanceMetric, flags.DistanceMetric, "m", fmt.Sprintf("The distance metric for the index. Valid values: %s", strings.Join(flags.DistanceMetricEnum(), ", "))) //nolint:lll // For readability + flagSet.StringToStringVar(&indexCreateFlags.indexLabels, flags.IndexLabels, nil, "Optional labels to assign to the index. Example: \"model=all-MiniLM-L6-v2,foo=bar\"") //nolint:lll // For readability //nolint:lll // For readability + flagSet.Var(&indexCreateFlags.storageNamespace, flags.StorageNamespace, "Optional storage namespace where the index is stored. Defaults to the index namespace.") //nolint:lll // For readability //nolint:lll // For readability + flagSet.Var(&indexCreateFlags.storageSet, flags.StorageSet, "Optional storage set where the index is stored. Defaults to the index name.") //nolint:lll // For readability //nolint:lll // For readability + flagSet.Var(&indexCreateFlags.hnswMaxEdges, flags.MaxEdges, "Maximum number bi-directional links per HNSW vertex. Greater values of 'm' in general provide better recall for data with high dimensionality, while lower values work well for data with lower dimensionality. The storage space required for the index increases proportionally with 'm'.") //nolint:lll // For readability + flagSet.Var(&indexCreateFlags.hnswConstructionEf, flags.ConstructionEf, "The number of candidate nearest neighbors shortlisted during index creation. Larger values provide better recall at the cost of longer index update times. The default is 100.") //nolint:lll // For readability + flagSet.Var(&indexCreateFlags.hnswEf, flags.Ef, "The default number of candidate nearest neighbors shortlisted during search. Larger values provide better recall at the cost of longer search times. The default is 100.") //nolint:lll // For readability + flagSet.Var(&indexCreateFlags.hnswMaxMemQueueSize, flags.HnswMaxMemQueueSize, "Maximum size of in-memory queue for inserted/updated vector records.") //nolint:lll // For readability //nolint:lll // For readability flagSet.AddFlagSet(indexCreateFlags.clientFlags.NewClientFlagSet()) flagSet.AddFlagSet(indexCreateFlags.hnswBatch.NewFlagSet()) flagSet.AddFlagSet(indexCreateFlags.hnswCache.NewFlagSet()) diff --git a/cmd/indexDrop.go b/cmd/indexDrop.go index 1575ef9..93b2493 100644 --- a/cmd/indexDrop.go +++ b/cmd/indexDrop.go @@ -6,7 +6,6 @@ import ( "fmt" "log/slog" - commonFlags "github.com/aerospike/tools-common-go/flags" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -24,10 +23,10 @@ var indexDropFlags = &struct { func newIndexDropFlagSet() *pflag.FlagSet { flagSet := &pflag.FlagSet{} - flagSet.BoolVarP(&indexDropFlags.yes, flags.Yes, "y", false, commonFlags.DefaultWrapHelpString("When true do not prompt for confirmation.")) //nolint:lll // For readability - flagSet.StringVarP(&indexDropFlags.namespace, flags.Namespace, "n", "", commonFlags.DefaultWrapHelpString("The namespace for the index.")) //nolint:lll // For readability - flagSet.StringSliceVarP(&indexDropFlags.sets, flags.Sets, "s", nil, commonFlags.DefaultWrapHelpString("The sets for the index.")) //nolint:lll // For readability - flagSet.StringVarP(&indexDropFlags.indexName, flags.IndexName, "i", "", commonFlags.DefaultWrapHelpString("The name of the index.")) //nolint:lll // For readability + flagSet.BoolVarP(&indexDropFlags.yes, flags.Yes, "y", false, "When true do not prompt for confirmation.") //nolint:lll // For readability + flagSet.StringVarP(&indexDropFlags.namespace, flags.Namespace, "n", "", "The namespace for the index.") //nolint:lll // For readability + flagSet.StringSliceVarP(&indexDropFlags.sets, flags.Sets, "s", nil, "The sets for the index.") //nolint:lll // For readability + flagSet.StringVarP(&indexDropFlags.indexName, flags.IndexName, "i", "", "The name of the index.") //nolint:lll // For readability flagSet.AddFlagSet(indexDropFlags.clientFlags.NewClientFlagSet()) return flagSet diff --git a/cmd/indexGC.go b/cmd/indexGC.go index ff9a4cc..3e0ca70 100644 --- a/cmd/indexGC.go +++ b/cmd/indexGC.go @@ -6,7 +6,6 @@ import ( "fmt" "log/slog" - commonFlags "github.com/aerospike/tools-common-go/flags" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -23,9 +22,9 @@ var indexGCFlags = &struct { func newIndexGCFlagSet() *pflag.FlagSet { flagSet := &pflag.FlagSet{} - flagSet.StringVarP(&indexGCFlags.namespace, flags.Namespace, "n", "", commonFlags.DefaultWrapHelpString("The namespace for the index.")) //nolint:lll // For readability - flagSet.StringVarP(&indexGCFlags.indexName, flags.IndexName, "i", "", commonFlags.DefaultWrapHelpString("The name of the index.")) //nolint:lll // For readability - flagSet.VarP(&indexGCFlags.cutoffTime, flags.CutoffTime, "c", commonFlags.DefaultWrapHelpString("The cutoff time for gc.")) //nolint:lll // For readability + flagSet.StringVarP(&indexGCFlags.namespace, flags.Namespace, "n", "", "The namespace for the index.") //nolint:lll // For readability + flagSet.StringVarP(&indexGCFlags.indexName, flags.IndexName, "i", "", "The name of the index.") //nolint:lll // For readability + flagSet.VarP(&indexGCFlags.cutoffTime, flags.CutoffTime, "c", "The cutoff time for gc.") //nolint:lll // For readability flagSet.AddFlagSet(indexGCFlags.clientFlags.NewClientFlagSet()) return flagSet diff --git a/cmd/indexList.go b/cmd/indexList.go index a6eed26..ae3c3fa 100644 --- a/cmd/indexList.go +++ b/cmd/indexList.go @@ -8,7 +8,6 @@ import ( "sync" "github.com/aerospike/avs-client-go/protos" - commonFlags "github.com/aerospike/tools-common-go/flags" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -22,7 +21,7 @@ var indexListFlags = &struct { func newIndexListFlagSet() *pflag.FlagSet { flagSet := &pflag.FlagSet{} - flagSet.BoolVarP(&indexListFlags.verbose, flags.Verbose, "v", false, commonFlags.DefaultWrapHelpString("Print detailed index information.")) //nolint:lll // For readability + flagSet.BoolVarP(&indexListFlags.verbose, flags.Verbose, "v", false, "Print detailed index information.") //nolint:lll // For readability flagSet.AddFlagSet(indexListFlags.clientFlags.NewClientFlagSet()) return flagSet diff --git a/cmd/indexUpdate.go b/cmd/indexUpdate.go index 8a7ce7f..b380ee1 100644 --- a/cmd/indexUpdate.go +++ b/cmd/indexUpdate.go @@ -7,7 +7,6 @@ import ( "log/slog" "github.com/aerospike/avs-client-go/protos" - commonFlags "github.com/aerospike/tools-common-go/flags" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -35,11 +34,11 @@ var indexUpdateFlags = &struct { func newIndexUpdateFlagSet() *pflag.FlagSet { flagSet := &pflag.FlagSet{} - flagSet.BoolVarP(&indexUpdateFlags.yes, flags.Yes, "y", false, commonFlags.DefaultWrapHelpString("When true do not prompt for confirmation.")) //nolint:lll // For readability - flagSet.StringVarP(&indexUpdateFlags.namespace, flags.Namespace, "n", "", commonFlags.DefaultWrapHelpString("The namespace for the index.")) //nolint:lll // For readability - flagSet.StringVarP(&indexUpdateFlags.indexName, flags.IndexName, "i", "", commonFlags.DefaultWrapHelpString("The name of the index.")) //nolint:lll // For readability - flagSet.StringToStringVar(&indexUpdateFlags.indexLabels, flags.IndexLabels, nil, commonFlags.DefaultWrapHelpString("The distance metric for the index.")) //nolint:lll // For readability - flagSet.Var(&indexUpdateFlags.hnswMaxMemQueueSize, flags.HnswMaxMemQueueSize, commonFlags.DefaultWrapHelpString("Maximum size of in-memory queue for inserted/updated vector records.")) //nolint:lll // For readability + flagSet.BoolVarP(&indexUpdateFlags.yes, flags.Yes, "y", false, "When true do not prompt for confirmation.") //nolint:lll // For readability + flagSet.StringVarP(&indexUpdateFlags.namespace, flags.Namespace, "n", "", "The namespace for the index.") //nolint:lll // For readability + flagSet.StringVarP(&indexUpdateFlags.indexName, flags.IndexName, "i", "", "The name of the index.") //nolint:lll // For readability + flagSet.StringToStringVar(&indexUpdateFlags.indexLabels, flags.IndexLabels, nil, "The distance metric for the index.") //nolint:lll // For readability + flagSet.Var(&indexUpdateFlags.hnswMaxMemQueueSize, flags.HnswMaxMemQueueSize, "Maximum size of in-memory queue for inserted/updated vector records.") //nolint:lll // For readability flagSet.AddFlagSet(indexUpdateFlags.clientFlags.NewClientFlagSet()) flagSet.AddFlagSet(indexUpdateFlags.hnswBatch.NewFlagSet()) flagSet.AddFlagSet(indexUpdateFlags.hnswCache.NewFlagSet()) diff --git a/cmd/root.go b/cmd/root.go index 3abc2ab..621eb3d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,6 +12,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" "github.com/spf13/viper" + "golang.org/x/term" ) var lvl = new(slog.LevelVar) @@ -92,9 +93,22 @@ func init() { rootCmd.PersistentFlags().Var( &rootFlags.logLevel, flags.LogLevel, - common.DefaultWrapHelpString(fmt.Sprintf("Log level for additional details and debugging. Valid values: %s", strings.Join(flags.LogLevelEnum(), ", "))), //nolint:lll // For readability + fmt.Sprintf("Log level for additional details and debugging. Valid values: %s", strings.Join(flags.LogLevelEnum(), ", ")), //nolint:lll // For readability ) - common.SetupRoot(rootCmd, "aerospike-vector-search", Version) // TODO: Handle version + common.SetupRoot(rootCmd, "aerospike-vector-search", Version) + + // TODO: Add custom template for usage to take into account terminal width + // Ex: https://github.com/sigstore/cosign/pull/3011/files + // Below is the poor man version + width, _, err := term.GetSize(int(os.Stdout.Fd())) + if err == nil { + usageTemplate := rootCmd.UsageTemplate() + usageTemplate = strings.ReplaceAll(usageTemplate, ".FlagUsages", fmt.Sprintf(".FlagUsagesWrapped %d", width)) + rootCmd.SetUsageTemplate(usageTemplate) + } else { + logger.Debug("failed to get terminal width", slog.Any("error", err)) + } + viper.SetEnvPrefix("ASVEC") bindEnvs := []string{ diff --git a/cmd/userCreate.go b/cmd/userCreate.go index fd235bf..e7c4771 100644 --- a/cmd/userCreate.go +++ b/cmd/userCreate.go @@ -6,7 +6,6 @@ import ( "fmt" "log/slog" - commonFlags "github.com/aerospike/tools-common-go/flags" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -23,9 +22,9 @@ var userCreateFlags = &struct { func newUserCreateFlagSet() *pflag.FlagSet { flagSet := &pflag.FlagSet{} flagSet.AddFlagSet(userCreateFlags.clientFlags.NewClientFlagSet()) - flagSet.StringVar(&userCreateFlags.newUsername, flags.Name, "", commonFlags.DefaultWrapHelpString("The name of the new user.")) //nolint:lll // For readability - flagSet.StringVar(&userCreateFlags.newPassword, flags.NewPassword, "", commonFlags.DefaultWrapHelpString("The password for the new user. If a new password is not provided you you will be prompted to enter a new password.")) //nolint:lll // For readability - flagSet.StringSliceVar(&userCreateFlags.roles, flags.Roles, []string{}, commonFlags.DefaultWrapHelpString("The roles to assign to the new user. To see valid roles run 'asvec role ls'.")) //nolint:lll // For readability + flagSet.StringVar(&userCreateFlags.newUsername, flags.Name, "", "The name of the new user.") //nolint:lll // For readability + flagSet.StringVar(&userCreateFlags.newPassword, flags.NewPassword, "", "The password for the new user. If a new password is not provided you you will be prompted to enter a new password.") //nolint:lll // For readability + flagSet.StringSliceVar(&userCreateFlags.roles, flags.Roles, []string{}, "The roles to assign to the new user. To see valid roles run 'asvec role ls'.") //nolint:lll // For readability return flagSet } diff --git a/cmd/userDrop.go b/cmd/userDrop.go index da4e99d..8adda9a 100644 --- a/cmd/userDrop.go +++ b/cmd/userDrop.go @@ -6,7 +6,6 @@ import ( "fmt" "log/slog" - commonFlags "github.com/aerospike/tools-common-go/flags" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -22,7 +21,7 @@ var userDropFlags = &struct { func newUserDropFlagSet() *pflag.FlagSet { flagSet := &pflag.FlagSet{} flagSet.AddFlagSet(userDropFlags.clientFlags.NewClientFlagSet()) - flagSet.StringVar(&userDropFlags.dropUser, flags.Name, "", commonFlags.DefaultWrapHelpString("The name of the user to drop.")) //nolint:lll // For readability + flagSet.StringVar(&userDropFlags.dropUser, flags.Name, "", "The name of the user to drop.") //nolint:lll // For readability return flagSet } diff --git a/cmd/userGrant.go b/cmd/userGrant.go index 643b532..11b1a6c 100644 --- a/cmd/userGrant.go +++ b/cmd/userGrant.go @@ -8,7 +8,6 @@ import ( "log/slog" "strings" - commonFlags "github.com/aerospike/tools-common-go/flags" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -24,8 +23,8 @@ var userGrantFlags = &struct { func newUserGrantFlagSet() *pflag.FlagSet { flagSet := &pflag.FlagSet{} flagSet.AddFlagSet(userGrantFlags.clientFlags.NewClientFlagSet()) - flagSet.StringVar(&userGrantFlags.grantUser, flags.Name, "", commonFlags.DefaultWrapHelpString("The existing user to grant new roles")) //nolint:lll // For readability - flagSet.StringSliceVar(&userGrantFlags.roles, flags.Roles, []string{}, commonFlags.DefaultWrapHelpString("The roles to grant the existing user. New roles are added to a users existing roles.")) //nolint:lll // For readability + flagSet.StringVar(&userGrantFlags.grantUser, flags.Name, "", "The existing user to grant new roles") //nolint:lll // For readability + flagSet.StringSliceVar(&userGrantFlags.roles, flags.Roles, []string{}, "The roles to grant the existing user. New roles are added to a users existing roles.") //nolint:lll // For readability return flagSet } diff --git a/cmd/userNewPassword.go b/cmd/userNewPassword.go index d3ed667..ffdd911 100644 --- a/cmd/userNewPassword.go +++ b/cmd/userNewPassword.go @@ -6,7 +6,6 @@ import ( "fmt" "log/slog" - commonFlags "github.com/aerospike/tools-common-go/flags" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -23,8 +22,8 @@ var userNewPassFlags = &struct { func newUserNewPassFlagSet() *pflag.FlagSet { flagSet := &pflag.FlagSet{} flagSet.AddFlagSet(userNewPassFlags.clientFlags.NewClientFlagSet()) - flagSet.StringVar(&userNewPassFlags.username, flags.Name, "", commonFlags.DefaultWrapHelpString("The name of the user.")) //nolint:lll // For readability - flagSet.StringVar(&userNewPassFlags.password, flags.NewPassword, "", commonFlags.DefaultWrapHelpString("The new password for the user. If a new password is not provided you you will be prompted to enter a new password.")) //nolint:lll // For readability + flagSet.StringVar(&userNewPassFlags.username, flags.Name, "", "The name of the user.") //nolint:lll // For readability + flagSet.StringVar(&userNewPassFlags.password, flags.NewPassword, "", "The new password for the user. If a new password is not provided you you will be prompted to enter a new password.") //nolint:lll // For readability return flagSet } diff --git a/cmd/userRevoke.go b/cmd/userRevoke.go index 91615d5..6e879ad 100644 --- a/cmd/userRevoke.go +++ b/cmd/userRevoke.go @@ -8,7 +8,6 @@ import ( "log/slog" "strings" - commonFlags "github.com/aerospike/tools-common-go/flags" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -24,8 +23,8 @@ var userRevokeFlags = &struct { func newUserRevokeFlagSet() *pflag.FlagSet { flagSet := &pflag.FlagSet{} flagSet.AddFlagSet(userRevokeFlags.clientFlags.NewClientFlagSet()) - flagSet.StringVar(&userRevokeFlags.revokeUser, flags.Name, "", commonFlags.DefaultWrapHelpString("The existing user to revoke new roles.")) //nolint:lll // For readability - flagSet.StringSliceVar(&userRevokeFlags.roles, flags.Roles, []string{}, commonFlags.DefaultWrapHelpString("The roles to revoke from the user. Roles are removed from a user's existing roles.")) //nolint:lll // For readability + flagSet.StringVar(&userRevokeFlags.revokeUser, flags.Name, "", "The existing user to revoke new roles.") //nolint:lll // For readability + flagSet.StringSliceVar(&userRevokeFlags.roles, flags.Roles, []string{}, "The roles to revoke from the user. Roles are removed from a user's existing roles.") //nolint:lll // For readability return flagSet }