in bydbctl/internal/cmd/index_rule_binding.go [35:145]
func newIndexRuleBindingCmd() *cobra.Command {
indexRuleBindingCmd := &cobra.Command{
Use: "indexRuleBinding",
Version: version.Build(),
Short: "IndexRuleBinding operation",
}
createCmd := &cobra.Command{
Use: "create -f [file|dir|-]",
Version: version.Build(),
Short: "Create indexRuleBindings from files",
RunE: func(cmd *cobra.Command, _ []string) error {
return rest(func() ([]reqBody, error) { return parseNameAndGroupFromYAML(cmd.InOrStdin()) },
func(request request) (*resty.Response, error) {
s := new(databasev1.IndexRuleBinding)
err := protojson.Unmarshal(request.data, s)
if err != nil {
return nil, err
}
cr := &databasev1.IndexRuleBindingRegistryServiceCreateRequest{
IndexRuleBinding: s,
}
b, err := protojson.Marshal(cr)
if err != nil {
return nil, err
}
return request.req.SetBody(b).Post(getPath(indexRuleBindingSchemaPath))
},
func(_ int, reqBody reqBody, _ []byte) error {
fmt.Printf("indexRuleBinding %s.%s is created", reqBody.group, reqBody.name)
fmt.Println()
return nil
}, enableTLS, insecure, cert)
},
}
updateCmd := &cobra.Command{
Use: "update -f [file|dir|-]",
Version: version.Build(),
Short: "Update indexRuleBindings from files",
RunE: func(cmd *cobra.Command, _ []string) (err error) {
return rest(func() ([]reqBody, error) { return parseNameAndGroupFromYAML(cmd.InOrStdin()) },
func(request request) (*resty.Response, error) {
s := new(databasev1.IndexRuleBinding)
err := protojson.Unmarshal(request.data, s)
if err != nil {
return nil, err
}
cr := &databasev1.IndexRuleBindingRegistryServiceUpdateRequest{
IndexRuleBinding: s,
}
b, err := protojson.Marshal(cr)
if err != nil {
return nil, err
}
return request.req.SetBody(b).
SetPathParam("name", request.name).SetPathParam("group", request.group).
Put(getPath(indexRuleBindingSchemaPathWithParams))
},
func(_ int, reqBody reqBody, _ []byte) error {
fmt.Printf("indexRuleBinding %s.%s is updated", reqBody.group, reqBody.name)
fmt.Println()
return nil
}, enableTLS, insecure, cert)
},
}
getCmd := &cobra.Command{
Use: "get [-g group] -n name",
Version: version.Build(),
Short: "Get a indexRuleBinding",
RunE: func(_ *cobra.Command, _ []string) (err error) {
return rest(parseFromFlags, func(request request) (*resty.Response, error) {
return request.req.SetPathParam("name", request.name).SetPathParam("group", request.group).Get(getPath(indexRuleBindingSchemaPathWithParams))
}, yamlPrinter, enableTLS, insecure, cert)
},
}
deleteCmd := &cobra.Command{
Use: "delete [-g group] -n name",
Version: version.Build(),
Short: "Delete a indexRuleBinding",
RunE: func(_ *cobra.Command, _ []string) (err error) {
return rest(parseFromFlags, func(request request) (*resty.Response, error) {
return request.req.SetPathParam("name", request.name).SetPathParam("group", request.group).Delete(getPath(indexRuleBindingSchemaPathWithParams))
}, func(_ int, reqBody reqBody, _ []byte) error {
fmt.Printf("indexRuleBinding %s.%s is deleted", reqBody.group, reqBody.name)
fmt.Println()
return nil
}, enableTLS, insecure, cert)
},
}
bindNameFlag(getCmd, deleteCmd)
listCmd := &cobra.Command{
Use: "list [-g group]",
Version: version.Build(),
Short: "List indexRuleBindings",
RunE: func(_ *cobra.Command, _ []string) (err error) {
return rest(parseFromFlags, func(request request) (*resty.Response, error) {
return request.req.SetPathParam("group", request.group).Get(getPath("/api/v1/index-rule-binding/schema/lists/{group}"))
}, yamlPrinter, enableTLS, insecure, cert)
},
}
bindFileFlag(createCmd, updateCmd)
bindTLSRelatedFlag(getCmd, createCmd, deleteCmd, updateCmd, listCmd)
indexRuleBindingCmd.AddCommand(getCmd, createCmd, deleteCmd, updateCmd, listCmd)
return indexRuleBindingCmd
}