-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jesse Schmidt
committed
May 22, 2024
1 parent
4ef27d9
commit 5a91438
Showing
5 changed files
with
245 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// deleteCmd represents the delete command | ||
var deleteCmd = &cobra.Command{ | ||
Use: "delete", | ||
Short: "A brief description of your command", | ||
Long: `A longer description that spans multiple lines and likely contains examples | ||
and usage of using your command. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("delete called") | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(deleteCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// deleteCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// deleteCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// deleteIndexCmd represents the deleteIndex command | ||
var deleteIndexCmd = &cobra.Command{ | ||
Use: "deleteIndex", | ||
Short: "A brief description of your command", | ||
Long: `A longer description that spans multiple lines and likely contains examples | ||
and usage of using your command. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("deleteIndex called") | ||
}, | ||
} | ||
|
||
func init() { | ||
deleteCmd.AddCommand(deleteIndexCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// deleteIndexCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// deleteIndexCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"strings" | ||
|
||
"github.com/aerospike/aerospike-proximus-client-go/protos" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
const ( | ||
flagNameSeeds = "seeds" | ||
flagNamePort = "port" | ||
flagNameNamespace = "namespace" | ||
flagNameSets = "sets" | ||
flagNameIndexName = "index-name" | ||
flagNameVector = "vector-field" | ||
flagNameDimension = "dimension" | ||
flagNameDistance = "distance-metric" | ||
flagNameIndexMeta = "index-meta" | ||
) | ||
|
||
type FlagSetBuilder struct { | ||
*pflag.FlagSet | ||
} | ||
|
||
func NewFlagSetBuilder(flagSet *pflag.FlagSet) *FlagSetBuilder { | ||
return &FlagSetBuilder{ | ||
flagSet, | ||
} | ||
} | ||
|
||
// TODO: Should this be a list of IPs? Should we support IP:PORT? | ||
func (fsb *FlagSetBuilder) AddSeedFlag() { | ||
fsb.IPP(flagNameSeeds, "h", net.ParseIP("127.0.0.1"), "The AVS seed host for cluster discovery.") | ||
} | ||
|
||
func (fsb *FlagSetBuilder) AddPortFlag() { | ||
fsb.IntP(flagNamePort, "p", 5000, "The AVS seed port for cluster discovery.") | ||
} | ||
|
||
func (fsb *FlagSetBuilder) AddNamespaceFlag() { | ||
fsb.StringP(flagNameNamespace, "n", "", "The namespace for the index.") | ||
} | ||
|
||
func (fsb *FlagSetBuilder) AddSetsFlag() { | ||
fsb.StringArrayP(flagNameSets, "s", nil, "The sets for the index.") | ||
} | ||
|
||
func (fsb *FlagSetBuilder) AddIndexNameFlag() { | ||
fsb.StringP(flagNameIndexName, "i", "", "The name of the index.") | ||
|
||
} | ||
|
||
func (fsb *FlagSetBuilder) AddVectorFieldFlag() { | ||
fsb.StringP(flagNameVector, "v", "vector-field", "The name of the vector field.") | ||
|
||
} | ||
|
||
func (fsb *FlagSetBuilder) AddDimensionFlag() { | ||
fsb.IntP(flagNameDimension, "d", 0, "The dimension of the vector field.") | ||
|
||
} | ||
|
||
func (fsb *FlagSetBuilder) AddDistanceMetricFlag() { | ||
distMetric := DistanceMetricFlag("") | ||
fsb.VarP(&distMetric, "distance-metric", "m", "The distance metric for the index.") | ||
} | ||
|
||
func (fsb *FlagSetBuilder) AddIndexMetaFlag() { | ||
fsb.StringToStringP(flagNameIndexMeta, "e", nil, "The metadata for the index.") | ||
} | ||
|
||
type DistanceMetricFlag string | ||
|
||
// This is just a set of valid VectorDistanceMetrics. The value does not have meaning | ||
var distanceMetricSet = protos.VectorDistanceMetric_value | ||
|
||
func (mode *DistanceMetricFlag) Set(val string) error { | ||
val = strings.ToUpper(val) | ||
if val, ok := distanceMetricSet[val]; ok { | ||
*mode = DistanceMetricFlag(val) | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("unrecognized distance metric") | ||
} | ||
|
||
func (mode *DistanceMetricFlag) Type() string { | ||
names := []string{} | ||
|
||
for key := range distanceMetricSet { | ||
names = append(names, key) | ||
} | ||
|
||
return strings.Join(names, ",") | ||
} | ||
|
||
func (mode *DistanceMetricFlag) String() string { | ||
return string(*mode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters