Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for boolean types #67

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions cmd/update_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,38 @@ import (
"sigs.k8s.io/yaml"
)

const updateAPILongHelp = `Command to update the Promise API.

It can be used to update the API GVK, or to add/remove properties to the API.

The --group, --kind, --version, and --plural flags are used to update the API
GVK. The --property flag is used to add or remove properties from the API. The
format is PROPERTY-NAME:TYPE. Valid types are string, number, integer, object,
and boolean.

For object types, the property name can be nested using the '.' character.

To remove a property, append a '-' to the property name.`

var updateAPICmd = &cobra.Command{
Use: "api --property PROPERTY-NAME:TYPE",
Short: "Command to update promise API",
Long: "Command to update promise API",
Example: ` # add a new property of type string to the API
kratix update api --property region:string
Long: updateAPILongHelp,
Example: ` # add a new property of type string to the API kratix update api
--property region:string

# add an integer 'port' property nested into a 'service' object
kratix update api --property service.port:integer

# removes the property from the API
kratix update api --property region-

# updates the API group and the Kind
kratix update api --group myorg.com --kind Database

# updates the version and the plural form
kratix update api --version v1beta3 --plural mydbs`,
kratix update api --version v1beta3 --plural mydbs
`,
RunE: UpdateAPI,
}

Expand Down Expand Up @@ -146,7 +160,7 @@ func updateCRDBytes(crd *apiextensionsv1.CustomResourceDefinition) ([]byte, erro
propNames := strings.Split(parsedProps[0], ".")
propType := parsedProps[1]

if !slices.Contains([]string{"string", "number", "integer", "object"}, propType) {
if !slices.Contains([]string{"string", "number", "integer", "object", "boolean"}, propType) {
return nil, fmt.Errorf("unsupported property type: %s", propType)
}

Expand Down
2 changes: 1 addition & 1 deletion test/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var _ = Describe("update", func() {
When("called with --help", func() {
It("prints the help", func() {
session := r.run("update", "api", "--help")
Expect(session.Out).To(gbytes.Say("Command to update promise API"))
Expect(session.Out).To(gbytes.Say("Command to update the Promise API"))
})
})

Expand Down