diff --git a/client/gatway_client.go b/client/gatway_client.go index 079b449..eca7214 100644 --- a/client/gatway_client.go +++ b/client/gatway_client.go @@ -88,7 +88,7 @@ func (client *GatewayClient) Get(kind *schema.Kind, parentPathValue []string) ([ return result, err } -func (client *GatewayClient) GetAliasTopics(kind *schema.Kind, param map[string]string) ([]resource.Resource, error) { +func (client *GatewayClient) ListKindWithFilters(kind *schema.Kind, param map[string]string) ([]resource.Resource, error) { var result []resource.Resource url := client.baseUrl + kind.ListPath(nil) req := client.client.R() @@ -130,7 +130,7 @@ func (client *GatewayClient) Delete(kind *schema.Kind, parentPathValue []string, return err } -func (client *GatewayClient) DeleteAliasTopics(kind *schema.Kind, param map[string]string) error { +func (client *GatewayClient) DeleteKindByNameAndVCluster(kind *schema.Kind, param map[string]string) error { url := client.baseUrl + kind.ListPath(nil) req := client.client.R() req.SetBody( diff --git a/cmd/delete.go b/cmd/delete.go index 2797b00..c2e561d 100644 --- a/cmd/delete.go +++ b/cmd/delete.go @@ -41,8 +41,8 @@ func initDelete(kinds schema.KindCatalog) { deleteCmd.MarkFlagRequired("file") for name, kind := range kinds { - if name == "AliasTopics" { - aliasTopicDeleteCmd := buildDeleteAliasTopicCmd(name, kind) + if name == "AliasTopics" || name == "ConcentrationRules" { + aliasTopicDeleteCmd := buildDeleteByVClusterAndNameCmd(name, kind) deleteCmd.AddCommand(aliasTopicDeleteCmd) } else { flags := kind.GetFlag() @@ -78,14 +78,14 @@ func initDelete(kinds schema.KindCatalog) { } } -func buildDeleteAliasTopicCmd(name string, kind schema.Kind) *cobra.Command { +func buildDeleteByVClusterAndNameCmd(name string, kind schema.Kind) *cobra.Command { const nameFlag = "name" const vClusterFlag = "vcluster" var nameValue string var vClusterValue string var aliasTopicDeleteCmd = &cobra.Command{ Use: fmt.Sprintf("%s [name]", name), - Short: "Delete an Alias Topic", + Short: "Delete resource of kind " + kind.GetName(), Args: cobra.ExactArgs(0), Aliases: []string{strings.ToLower(name), strings.ToLower(name) + "s", name + "s"}, Run: func(cmd *cobra.Command, args []string) { @@ -100,7 +100,7 @@ func buildDeleteAliasTopicCmd(name string, kind schema.Kind) *cobra.Command { queryParams[vClusterFlag] = "passthrough" } - err = gatewayApiClient().DeleteAliasTopics(&kind, queryParams) + err = gatewayApiClient().DeleteKindByNameAndVCluster(&kind, queryParams) if err != nil { fmt.Fprintf(os.Stderr, "%s\n", err) os.Exit(1) @@ -108,8 +108,8 @@ func buildDeleteAliasTopicCmd(name string, kind schema.Kind) *cobra.Command { }, } - aliasTopicDeleteCmd.Flags().StringVar(&nameValue, nameFlag, "", "name of the alias topic") - aliasTopicDeleteCmd.Flags().StringVar(&vClusterValue, "vCluster", "", "vCluster of the alias topic") + aliasTopicDeleteCmd.Flags().StringVar(&nameValue, nameFlag, "", "name of the "+kind.GetName()) + aliasTopicDeleteCmd.Flags().StringVar(&vClusterValue, vClusterFlag, "", "vCluster of the "+kind.GetName()) aliasTopicDeleteCmd.MarkFlagRequired(nameFlag) aliasTopicDeleteCmd.MarkFlagRequired(vClusterFlag) diff --git a/cmd/get.go b/cmd/get.go index b66bf19..b57c665 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -25,8 +25,8 @@ func initGet(kinds schema.KindCatalog) { rootCmd.AddCommand(getCmd) for name, kind := range kinds { - if name == "AliasTopics" { - aliasTopicGetCmd := buildGetAliasTopicCmd(name, kind) + if name == "AliasTopics" || name == "ConcentrationRules" { + aliasTopicGetCmd := buildListFilteredByVClusterOrNameCmd(name, kind) getCmd.AddCommand(aliasTopicGetCmd) } else { flags := kind.GetFlag() @@ -74,7 +74,7 @@ func initGet(kinds schema.KindCatalog) { } } -func buildGetAliasTopicCmd(name string, kind schema.Kind) *cobra.Command { +func buildListFilteredByVClusterOrNameCmd(name string, kind schema.Kind) *cobra.Command { const nameFlag = "name" const vClusterFlag = "vcluster" const showDefaultsFlag = "showDefaults" @@ -83,7 +83,7 @@ func buildGetAliasTopicCmd(name string, kind schema.Kind) *cobra.Command { var showDefaultsValue string var aliasTopicGetCmd = &cobra.Command{ Use: fmt.Sprintf("%s [name]", name), - Short: "List Alias Topics", + Short: "Get resource of kind " + kind.GetName(), Args: cobra.ExactArgs(0), Aliases: []string{strings.ToLower(name), strings.ToLower(name) + "s", name + "s"}, Run: func(cmd *cobra.Command, args []string) { @@ -100,7 +100,7 @@ func buildGetAliasTopicCmd(name string, kind schema.Kind) *cobra.Command { queryParams[showDefaultsFlag] = showDefaultsValue } - result, err = gatewayApiClient().GetAliasTopics(&kind, queryParams) + result, err = gatewayApiClient().ListKindWithFilters(&kind, queryParams) for _, r := range result { r.PrintPreservingOriginalFieldOrder() fmt.Println("---") @@ -112,8 +112,8 @@ func buildGetAliasTopicCmd(name string, kind schema.Kind) *cobra.Command { }, } - aliasTopicGetCmd.Flags().StringVar(&nameValue, nameFlag, "", "filter the alias topic result list by name") - aliasTopicGetCmd.Flags().StringVar(&vClusterValue, "vCluster", "", "filter the alias topic result list by vcluster") + aliasTopicGetCmd.Flags().StringVar(&nameValue, nameFlag, "", "filter the "+kind.GetName()+" result list by name") + aliasTopicGetCmd.Flags().StringVar(&vClusterValue, vClusterFlag, "", "filter the "+kind.GetName()+" result list by vcluster") aliasTopicGetCmd.Flags().StringVar(&showDefaultsValue, "showDefaults", "", "Toggle show defaults values (true|false, default false)") return aliasTopicGetCmd