From e9ac2205234ee7b0cc12a27701d72fa4a195af1e Mon Sep 17 00:00:00 2001 From: FingerLeader Date: Tue, 20 Aug 2024 23:34:42 +0800 Subject: [PATCH 1/9] add create branch from timestamp Signed-off-by: FingerLeader --- internal/cli/serverless/branch/create.go | 32 ++++++++++++++++--- internal/flag/flag.go | 1 + .../v1beta1/branch/branch.swagger.json | 5 +++ .../v1beta1/branch/models/branch_state.go | 3 +- .../v1beta1/branch/models/v1beta1_branch.go | 20 ++++++++++++ 5 files changed, 54 insertions(+), 7 deletions(-) diff --git a/internal/cli/serverless/branch/create.go b/internal/cli/serverless/branch/create.go index c91850ca..2993d39a 100644 --- a/internal/cli/serverless/branch/create.go +++ b/internal/cli/serverless/branch/create.go @@ -31,12 +31,14 @@ import ( "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" "github.com/fatih/color" + "github.com/go-openapi/strfmt" "github.com/juju/errors" "github.com/spf13/cobra" ) var createBranchField = map[string]int{ - flag.DisplayName: 0, + flag.DisplayName: 0, + flag.ParentTimestamp: 1, } const ( @@ -108,6 +110,7 @@ func CreateCmd(h *internal.Helper) *cobra.Command { var branchName string var clusterId string var parentID string + var parentTimestampStr string if opts.interactive { if !h.IOStreams.CanPrompt { return errors.New("The terminal doesn't support interactive mode, please use non-interactive mode") @@ -138,6 +141,7 @@ func CreateCmd(h *internal.Helper) *cobra.Command { if len(branchName) == 0 { return errors.New("branch name is required") } + parentTimestampStr = inputModel.(ui.TextInputModel).Inputs[createBranchField[flag.ParentTimestamp]].Value() } else { // non-interactive mode, get values from flags var err error @@ -153,11 +157,26 @@ func CreateCmd(h *internal.Helper) *cobra.Command { if err != nil { return errors.Trace(err) } + parentTimestampStr, err = cmd.Flags().GetString(flag.ParentTimestamp) + if err != nil { + return errors.Trace(err) + } + } + + _, err = time.Parse(time.RFC3339, parentTimestampStr) + if err != nil { + return errors.New("Invalid parent timestamp format, please use RFC3339 format") + } + + parentTimestamp, err := strfmt.ParseDateTime(parentTimestampStr) + if err != nil { + return errors.Trace(err) } params := branchApi.NewBranchServiceCreateBranchParams().WithClusterID(clusterId).WithBranch(&branchModel.V1beta1Branch{ - DisplayName: &branchName, - ParentID: parentID, + DisplayName: &branchName, + ParentID: parentID, + ParentTimestamp: parentTimestamp, }).WithContext(ctx) if h.IOStreams.CanPrompt { @@ -179,6 +198,7 @@ func CreateCmd(h *internal.Helper) *cobra.Command { createCmd.Flags().StringP(flag.DisplayName, flag.DisplayNameShort, "", "The displayName of the branch to be created.") createCmd.Flags().StringP(flag.ClusterID, flag.ClusterIDShort, "", "The ID of the cluster, in which the branch will be created.") createCmd.Flags().StringP(flag.ParentID, "", "", "The ID of the branch parent, default is cluster id.") + createCmd.Flags().StringP(flag.ParentTimestamp, "", "", "The timestamp of the parent branch, default is current time.") return createCmd } @@ -280,9 +300,11 @@ func initialCreateBranchInputModel() ui.TextInputModel { t.Focus() t.PromptStyle = config.FocusedStyle t.TextStyle = config.FocusedStyle - - m.Inputs[v] = t + case flag.ParentTimestamp: + timestampExample := time.Now().Format(time.RFC3339) + t.Placeholder = fmt.Sprintf("Parent Timestamp (e.g.: %s)", timestampExample) } + m.Inputs[v] = t } return m } diff --git a/internal/flag/flag.go b/internal/flag/flag.go index 4c192837..5bee47a4 100644 --- a/internal/flag/flag.go +++ b/internal/flag/flag.go @@ -78,6 +78,7 @@ const ( TableWhere string = "where" TableFilter string = "filter" ParentID string = "parent-id" + ParentTimestamp string = "parent-timestamp" PublicEndpointDisabled string = "disable-public-endpoint" ) diff --git a/pkg/tidbcloud/v1beta1/branch/branch.swagger.json b/pkg/tidbcloud/v1beta1/branch/branch.swagger.json index ab87a5d7..f595dc6c 100644 --- a/pkg/tidbcloud/v1beta1/branch/branch.swagger.json +++ b/pkg/tidbcloud/v1beta1/branch/branch.swagger.json @@ -419,6 +419,11 @@ "parentDisplayName": { "type": "string", "description": "OPTIONAL. The parent display name of this branch." + }, + "parentTimestamp": { + "type": "string", + "format": "date-time", + "description": "OPTIONAL. The parent timestamp of this branch." } }, "title": "Message for branch", diff --git a/pkg/tidbcloud/v1beta1/branch/models/branch_state.go b/pkg/tidbcloud/v1beta1/branch/models/branch_state.go index 9bbbf458..0789137d 100644 --- a/pkg/tidbcloud/v1beta1/branch/models/branch_state.go +++ b/pkg/tidbcloud/v1beta1/branch/models/branch_state.go @@ -16,13 +16,12 @@ import ( // BranchState Output Only. Branch State. // -// - STATE_UNSPECIFIED: The state of the branch is unknown. // - CREATING: The branch is being created. // - ACTIVE: The branch is active and running. // - DELETED: The branch is being deleted. // - MAINTENANCE: The branch is under maintenance. // -// swagger:model BranchState +// swagger:model Branch.State type BranchState string func NewBranchState(value BranchState) *BranchState { diff --git a/pkg/tidbcloud/v1beta1/branch/models/v1beta1_branch.go b/pkg/tidbcloud/v1beta1/branch/models/v1beta1_branch.go index 7e8cd230..75c090dc 100644 --- a/pkg/tidbcloud/v1beta1/branch/models/v1beta1_branch.go +++ b/pkg/tidbcloud/v1beta1/branch/models/v1beta1_branch.go @@ -56,6 +56,10 @@ type V1beta1Branch struct { // OPTIONAL. The parent ID of this branch. ParentID string `json:"parentId,omitempty"` + // OPTIONAL. The parent timestamp of this branch. + // Format: date-time + ParentTimestamp strfmt.DateTime `json:"parentTimestamp,omitempty"` + // Output only. The state of this branch. // Read Only: true State V1beta1BranchState `json:"state,omitempty"` @@ -91,6 +95,10 @@ func (m *V1beta1Branch) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateParentTimestamp(formats); err != nil { + res = append(res, err) + } + if err := m.validateState(formats); err != nil { res = append(res, err) } @@ -149,6 +157,18 @@ func (m *V1beta1Branch) validateEndpoints(formats strfmt.Registry) error { return nil } +func (m *V1beta1Branch) validateParentTimestamp(formats strfmt.Registry) error { + if swag.IsZero(m.ParentTimestamp) { // not required + return nil + } + + if err := validate.FormatOf("parentTimestamp", "body", "date-time", m.ParentTimestamp.String(), formats); err != nil { + return err + } + + return nil +} + func (m *V1beta1Branch) validateState(formats strfmt.Registry) error { if swag.IsZero(m.State) { // not required return nil From 28022d989a29a0de1e3e314a7c2ebc70f0d6e23a Mon Sep 17 00:00:00 2001 From: FingerLeader Date: Wed, 21 Aug 2024 00:00:35 +0800 Subject: [PATCH 2/9] fix Signed-off-by: FingerLeader --- internal/cli/serverless/branch/create.go | 20 ++++++++----------- .../cli/serverless/branch/describe_test.go | 1 + internal/cli/serverless/branch/list_test.go | 3 +++ .../v1beta1/branch/branch.swagger.json | 1 - .../v1beta1/branch/models/v1beta1_branch.go | 19 +----------------- 5 files changed, 13 insertions(+), 31 deletions(-) diff --git a/internal/cli/serverless/branch/create.go b/internal/cli/serverless/branch/create.go index 2993d39a..08fdc599 100644 --- a/internal/cli/serverless/branch/create.go +++ b/internal/cli/serverless/branch/create.go @@ -31,7 +31,6 @@ import ( "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" "github.com/fatih/color" - "github.com/go-openapi/strfmt" "github.com/juju/errors" "github.com/spf13/cobra" ) @@ -110,7 +109,7 @@ func CreateCmd(h *internal.Helper) *cobra.Command { var branchName string var clusterId string var parentID string - var parentTimestampStr string + var parentTimestamp string if opts.interactive { if !h.IOStreams.CanPrompt { return errors.New("The terminal doesn't support interactive mode, please use non-interactive mode") @@ -141,7 +140,7 @@ func CreateCmd(h *internal.Helper) *cobra.Command { if len(branchName) == 0 { return errors.New("branch name is required") } - parentTimestampStr = inputModel.(ui.TextInputModel).Inputs[createBranchField[flag.ParentTimestamp]].Value() + parentTimestamp = inputModel.(ui.TextInputModel).Inputs[createBranchField[flag.ParentTimestamp]].Value() } else { // non-interactive mode, get values from flags var err error @@ -157,20 +156,17 @@ func CreateCmd(h *internal.Helper) *cobra.Command { if err != nil { return errors.Trace(err) } - parentTimestampStr, err = cmd.Flags().GetString(flag.ParentTimestamp) + parentTimestamp, err = cmd.Flags().GetString(flag.ParentTimestamp) if err != nil { return errors.Trace(err) } } - _, err = time.Parse(time.RFC3339, parentTimestampStr) - if err != nil { - return errors.New("Invalid parent timestamp format, please use RFC3339 format") - } - - parentTimestamp, err := strfmt.ParseDateTime(parentTimestampStr) - if err != nil { - return errors.Trace(err) + if len(parentTimestamp) != 0 { + _, err = time.Parse(time.RFC3339, parentTimestamp) + if err != nil { + return errors.New("Invalid parent timestamp format, please use RFC3339 format") + } } params := branchApi.NewBranchServiceCreateBranchParams().WithClusterID(clusterId).WithBranch(&branchModel.V1beta1Branch{ diff --git a/internal/cli/serverless/branch/describe_test.go b/internal/cli/serverless/branch/describe_test.go index f20b0129..181b5182 100644 --- a/internal/cli/serverless/branch/describe_test.go +++ b/internal/cli/serverless/branch/describe_test.go @@ -50,6 +50,7 @@ const getBranchResultStr = `{ }, "name": "clusters/10202848322613926203/branches/bran-fgwdnpasmrahnh5iozqawnmijq", "parentId": "10202848322613926203", + "parentTimestamp": "0001-01-01T00:00:00.000Z", "state": "ACTIVE", "updateTime": "2023-12-11T09:44:05.000Z", "usage": { diff --git a/internal/cli/serverless/branch/list_test.go b/internal/cli/serverless/branch/list_test.go index 7a20a26c..c70fe6b6 100644 --- a/internal/cli/serverless/branch/list_test.go +++ b/internal/cli/serverless/branch/list_test.go @@ -43,6 +43,7 @@ const listResultStr = `{ "displayName": "t", "name": "clusters/10202848322613926203/branches/bran-wscjvwen2jajdjiy7hawcebxke", "parentId": "10202848322613926203", + "parentTimestamp": "0001-01-01T00:00:00.000Z", "state": "ACTIVE", "updateTime": "2023-12-12T10:18:24.000Z" } @@ -61,6 +62,7 @@ const listResultMultiPageStr = `{ "displayName": "t", "name": "clusters/10202848322613926203/branches/bran-wscjvwen2jajdjiy7hawcebxke", "parentId": "10202848322613926203", + "parentTimestamp": "0001-01-01T00:00:00.000Z", "state": "ACTIVE", "updateTime": "2023-12-12T10:18:24.000Z" }, @@ -72,6 +74,7 @@ const listResultMultiPageStr = `{ "displayName": "t", "name": "clusters/10202848322613926203/branches/bran-wscjvwen2jajdjiy7hawcebxke", "parentId": "10202848322613926203", + "parentTimestamp": "0001-01-01T00:00:00.000Z", "state": "ACTIVE", "updateTime": "2023-12-12T10:18:24.000Z" } diff --git a/pkg/tidbcloud/v1beta1/branch/branch.swagger.json b/pkg/tidbcloud/v1beta1/branch/branch.swagger.json index f595dc6c..ee09e405 100644 --- a/pkg/tidbcloud/v1beta1/branch/branch.swagger.json +++ b/pkg/tidbcloud/v1beta1/branch/branch.swagger.json @@ -422,7 +422,6 @@ }, "parentTimestamp": { "type": "string", - "format": "date-time", "description": "OPTIONAL. The parent timestamp of this branch." } }, diff --git a/pkg/tidbcloud/v1beta1/branch/models/v1beta1_branch.go b/pkg/tidbcloud/v1beta1/branch/models/v1beta1_branch.go index 75c090dc..81f7ad0e 100644 --- a/pkg/tidbcloud/v1beta1/branch/models/v1beta1_branch.go +++ b/pkg/tidbcloud/v1beta1/branch/models/v1beta1_branch.go @@ -57,8 +57,7 @@ type V1beta1Branch struct { ParentID string `json:"parentId,omitempty"` // OPTIONAL. The parent timestamp of this branch. - // Format: date-time - ParentTimestamp strfmt.DateTime `json:"parentTimestamp,omitempty"` + ParentTimestamp string `json:"parentTimestamp,omitempty"` // Output only. The state of this branch. // Read Only: true @@ -95,10 +94,6 @@ func (m *V1beta1Branch) Validate(formats strfmt.Registry) error { res = append(res, err) } - if err := m.validateParentTimestamp(formats); err != nil { - res = append(res, err) - } - if err := m.validateState(formats); err != nil { res = append(res, err) } @@ -157,18 +152,6 @@ func (m *V1beta1Branch) validateEndpoints(formats strfmt.Registry) error { return nil } -func (m *V1beta1Branch) validateParentTimestamp(formats strfmt.Registry) error { - if swag.IsZero(m.ParentTimestamp) { // not required - return nil - } - - if err := validate.FormatOf("parentTimestamp", "body", "date-time", m.ParentTimestamp.String(), formats); err != nil { - return err - } - - return nil -} - func (m *V1beta1Branch) validateState(formats strfmt.Registry) error { if swag.IsZero(m.State) { // not required return nil From 94feeb8bb8cde34481046e100cd6004db8a7defe Mon Sep 17 00:00:00 2001 From: FingerLeader Date: Wed, 28 Aug 2024 00:40:11 +0800 Subject: [PATCH 3/9] regenerate parentTimestamp Signed-off-by: FingerLeader --- internal/cli/serverless/branch/create.go | 14 ++++++++----- .../v1beta1/branch/branch.swagger.json | 4 +++- .../v1beta1/branch/models/v1beta1_branch.go | 21 +++++++++++++++++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/internal/cli/serverless/branch/create.go b/internal/cli/serverless/branch/create.go index 08fdc599..2d96efa5 100644 --- a/internal/cli/serverless/branch/create.go +++ b/internal/cli/serverless/branch/create.go @@ -31,6 +31,7 @@ import ( "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" "github.com/fatih/color" + "github.com/go-openapi/strfmt" "github.com/juju/errors" "github.com/spf13/cobra" ) @@ -109,7 +110,8 @@ func CreateCmd(h *internal.Helper) *cobra.Command { var branchName string var clusterId string var parentID string - var parentTimestamp string + var parentTimestampStr string + var parentTimestamp *strfmt.DateTime if opts.interactive { if !h.IOStreams.CanPrompt { return errors.New("The terminal doesn't support interactive mode, please use non-interactive mode") @@ -140,7 +142,7 @@ func CreateCmd(h *internal.Helper) *cobra.Command { if len(branchName) == 0 { return errors.New("branch name is required") } - parentTimestamp = inputModel.(ui.TextInputModel).Inputs[createBranchField[flag.ParentTimestamp]].Value() + parentTimestampStr = inputModel.(ui.TextInputModel).Inputs[createBranchField[flag.ParentTimestamp]].Value() } else { // non-interactive mode, get values from flags var err error @@ -156,17 +158,19 @@ func CreateCmd(h *internal.Helper) *cobra.Command { if err != nil { return errors.Trace(err) } - parentTimestamp, err = cmd.Flags().GetString(flag.ParentTimestamp) + parentTimestampStr, err = cmd.Flags().GetString(flag.ParentTimestamp) if err != nil { return errors.Trace(err) } } - if len(parentTimestamp) != 0 { - _, err = time.Parse(time.RFC3339, parentTimestamp) + if len(parentTimestampStr) != 0 { + t, err := time.Parse(time.RFC3339, parentTimestampStr) if err != nil { return errors.New("Invalid parent timestamp format, please use RFC3339 format") } + tFormated := strfmt.DateTime(t) + parentTimestamp = &tFormated } params := branchApi.NewBranchServiceCreateBranchParams().WithClusterID(clusterId).WithBranch(&branchModel.V1beta1Branch{ diff --git a/pkg/tidbcloud/v1beta1/branch/branch.swagger.json b/pkg/tidbcloud/v1beta1/branch/branch.swagger.json index ee09e405..d1447b60 100644 --- a/pkg/tidbcloud/v1beta1/branch/branch.swagger.json +++ b/pkg/tidbcloud/v1beta1/branch/branch.swagger.json @@ -422,7 +422,9 @@ }, "parentTimestamp": { "type": "string", - "description": "OPTIONAL. The parent timestamp of this branch." + "format": "date-time", + "x-nullable": true, + "description": "Optional. The point in time on the parent branch the branch will be created from." } }, "title": "Message for branch", diff --git a/pkg/tidbcloud/v1beta1/branch/models/v1beta1_branch.go b/pkg/tidbcloud/v1beta1/branch/models/v1beta1_branch.go index 81f7ad0e..50af2ec8 100644 --- a/pkg/tidbcloud/v1beta1/branch/models/v1beta1_branch.go +++ b/pkg/tidbcloud/v1beta1/branch/models/v1beta1_branch.go @@ -56,8 +56,9 @@ type V1beta1Branch struct { // OPTIONAL. The parent ID of this branch. ParentID string `json:"parentId,omitempty"` - // OPTIONAL. The parent timestamp of this branch. - ParentTimestamp string `json:"parentTimestamp,omitempty"` + // Optional. The point in time on the parent branch the branch will be created from. + // Format: date-time + ParentTimestamp *strfmt.DateTime `json:"parentTimestamp,omitempty"` // Output only. The state of this branch. // Read Only: true @@ -94,6 +95,10 @@ func (m *V1beta1Branch) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateParentTimestamp(formats); err != nil { + res = append(res, err) + } + if err := m.validateState(formats); err != nil { res = append(res, err) } @@ -152,6 +157,18 @@ func (m *V1beta1Branch) validateEndpoints(formats strfmt.Registry) error { return nil } +func (m *V1beta1Branch) validateParentTimestamp(formats strfmt.Registry) error { + if swag.IsZero(m.ParentTimestamp) { // not required + return nil + } + + if err := validate.FormatOf("parentTimestamp", "body", "date-time", m.ParentTimestamp.String(), formats); err != nil { + return err + } + + return nil +} + func (m *V1beta1Branch) validateState(formats strfmt.Registry) error { if swag.IsZero(m.State) { // not required return nil From 568650d2bead7b870cc7f63043b9e7bed2a286f6 Mon Sep 17 00:00:00 2001 From: FingerLeader Date: Wed, 28 Aug 2024 00:47:34 +0800 Subject: [PATCH 4/9] remove test parenttimestamp Signed-off-by: FingerLeader --- internal/cli/serverless/branch/list_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/internal/cli/serverless/branch/list_test.go b/internal/cli/serverless/branch/list_test.go index c70fe6b6..7a20a26c 100644 --- a/internal/cli/serverless/branch/list_test.go +++ b/internal/cli/serverless/branch/list_test.go @@ -43,7 +43,6 @@ const listResultStr = `{ "displayName": "t", "name": "clusters/10202848322613926203/branches/bran-wscjvwen2jajdjiy7hawcebxke", "parentId": "10202848322613926203", - "parentTimestamp": "0001-01-01T00:00:00.000Z", "state": "ACTIVE", "updateTime": "2023-12-12T10:18:24.000Z" } @@ -62,7 +61,6 @@ const listResultMultiPageStr = `{ "displayName": "t", "name": "clusters/10202848322613926203/branches/bran-wscjvwen2jajdjiy7hawcebxke", "parentId": "10202848322613926203", - "parentTimestamp": "0001-01-01T00:00:00.000Z", "state": "ACTIVE", "updateTime": "2023-12-12T10:18:24.000Z" }, @@ -74,7 +72,6 @@ const listResultMultiPageStr = `{ "displayName": "t", "name": "clusters/10202848322613926203/branches/bran-wscjvwen2jajdjiy7hawcebxke", "parentId": "10202848322613926203", - "parentTimestamp": "0001-01-01T00:00:00.000Z", "state": "ACTIVE", "updateTime": "2023-12-12T10:18:24.000Z" } From b59a29dfb7cbac40c929e1c588282561ba446735 Mon Sep 17 00:00:00 2001 From: FingerLeader Date: Wed, 28 Aug 2024 00:50:27 +0800 Subject: [PATCH 5/9] remove test parenttimestamp Signed-off-by: FingerLeader --- internal/cli/serverless/branch/describe_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/cli/serverless/branch/describe_test.go b/internal/cli/serverless/branch/describe_test.go index 181b5182..f20b0129 100644 --- a/internal/cli/serverless/branch/describe_test.go +++ b/internal/cli/serverless/branch/describe_test.go @@ -50,7 +50,6 @@ const getBranchResultStr = `{ }, "name": "clusters/10202848322613926203/branches/bran-fgwdnpasmrahnh5iozqawnmijq", "parentId": "10202848322613926203", - "parentTimestamp": "0001-01-01T00:00:00.000Z", "state": "ACTIVE", "updateTime": "2023-12-11T09:44:05.000Z", "usage": { From eb5b44f75525a1151dd391fdb7fd93afce84d174 Mon Sep 17 00:00:00 2001 From: FingerLeader Date: Wed, 28 Aug 2024 15:35:05 +0800 Subject: [PATCH 6/9] fix Signed-off-by: FingerLeader --- internal/cli/serverless/branch/create.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/cli/serverless/branch/create.go b/internal/cli/serverless/branch/create.go index 2d96efa5..e4149de8 100644 --- a/internal/cli/serverless/branch/create.go +++ b/internal/cli/serverless/branch/create.go @@ -54,6 +54,7 @@ func (c CreateOpts) NonInteractiveFlags() []string { return []string{ flag.DisplayName, flag.ClusterID, + flag.ParentTimestamp, } } @@ -198,7 +199,7 @@ func CreateCmd(h *internal.Helper) *cobra.Command { createCmd.Flags().StringP(flag.DisplayName, flag.DisplayNameShort, "", "The displayName of the branch to be created.") createCmd.Flags().StringP(flag.ClusterID, flag.ClusterIDShort, "", "The ID of the cluster, in which the branch will be created.") createCmd.Flags().StringP(flag.ParentID, "", "", "The ID of the branch parent, default is cluster id.") - createCmd.Flags().StringP(flag.ParentTimestamp, "", "", "The timestamp of the parent branch, default is current time.") + createCmd.Flags().StringP(flag.ParentTimestamp, "", "", "The timestamp of the parent branch, default is current time. (RFC3339 format, e.g.: 2024-01-01T00:00:00Z)") return createCmd } @@ -302,7 +303,7 @@ func initialCreateBranchInputModel() ui.TextInputModel { t.TextStyle = config.FocusedStyle case flag.ParentTimestamp: timestampExample := time.Now().Format(time.RFC3339) - t.Placeholder = fmt.Sprintf("Parent Timestamp (e.g.: %s)", timestampExample) + t.Placeholder = fmt.Sprintf("Parent Timestamp (optional, e.g.: %s)", timestampExample) } m.Inputs[v] = t } From e96e70e04f90d3f715ac20c8f72537103382a656 Mon Sep 17 00:00:00 2001 From: FingerLeader Date: Wed, 28 Aug 2024 16:30:03 +0800 Subject: [PATCH 7/9] fix Signed-off-by: FingerLeader --- internal/cli/serverless/branch/create.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/cli/serverless/branch/create.go b/internal/cli/serverless/branch/create.go index e4149de8..f1e407dd 100644 --- a/internal/cli/serverless/branch/create.go +++ b/internal/cli/serverless/branch/create.go @@ -58,6 +58,13 @@ func (c CreateOpts) NonInteractiveFlags() []string { } } +func (c CreateOpts) RequiredFlags() []string { + return []string{ + flag.ClusterID, + flag.DisplayName, + } +} + func (c *CreateOpts) MarkInteractive(cmd *cobra.Command) error { flags := c.NonInteractiveFlags() for _, fn := range flags { @@ -69,7 +76,7 @@ func (c *CreateOpts) MarkInteractive(cmd *cobra.Command) error { } // Mark required flags if !c.interactive { - for _, fn := range flags { + for _, fn := range c.RequiredFlags() { err := cmd.MarkFlagRequired(fn) if err != nil { return err From 51ae3113d178111e779d4cb5cdd0ae4a07e118e0 Mon Sep 17 00:00:00 2001 From: Xiang Zhang Date: Wed, 28 Aug 2024 21:57:32 +0800 Subject: [PATCH 8/9] Apply suggestions from code review --- internal/cli/serverless/branch/create.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cli/serverless/branch/create.go b/internal/cli/serverless/branch/create.go index f1e407dd..c43159fe 100644 --- a/internal/cli/serverless/branch/create.go +++ b/internal/cli/serverless/branch/create.go @@ -206,7 +206,7 @@ func CreateCmd(h *internal.Helper) *cobra.Command { createCmd.Flags().StringP(flag.DisplayName, flag.DisplayNameShort, "", "The displayName of the branch to be created.") createCmd.Flags().StringP(flag.ClusterID, flag.ClusterIDShort, "", "The ID of the cluster, in which the branch will be created.") createCmd.Flags().StringP(flag.ParentID, "", "", "The ID of the branch parent, default is cluster id.") - createCmd.Flags().StringP(flag.ParentTimestamp, "", "", "The timestamp of the parent branch, default is current time. (RFC3339 format, e.g.: 2024-01-01T00:00:00Z)") + createCmd.Flags().StringP(flag.ParentTimestamp, "", "", "The timestamp of the parent branch, default is current time. (RFC3339 format, e.g., 2024-01-01T00:00:00Z)") return createCmd } @@ -310,7 +310,7 @@ func initialCreateBranchInputModel() ui.TextInputModel { t.TextStyle = config.FocusedStyle case flag.ParentTimestamp: timestampExample := time.Now().Format(time.RFC3339) - t.Placeholder = fmt.Sprintf("Parent Timestamp (optional, e.g.: %s)", timestampExample) + t.Placeholder = fmt.Sprintf("Parent Timestamp (optional, e.g., %s)", timestampExample) } m.Inputs[v] = t } From 8a6b5faeee6e810ef4b5670ff093e57f40e4fb32 Mon Sep 17 00:00:00 2001 From: zhangyangyu Date: Wed, 28 Aug 2024 21:58:02 +0800 Subject: [PATCH 9/9] doc --- docs/generate_doc/ticloud_serverless_branch_create.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/generate_doc/ticloud_serverless_branch_create.md b/docs/generate_doc/ticloud_serverless_branch_create.md index c3545ab1..88d27fb2 100644 --- a/docs/generate_doc/ticloud_serverless_branch_create.md +++ b/docs/generate_doc/ticloud_serverless_branch_create.md @@ -19,10 +19,11 @@ ticloud serverless branch create [flags] ### Options ``` - -c, --cluster-id string The ID of the cluster, in which the branch will be created. - -n, --display-name string The displayName of the branch to be created. - -h, --help help for create - --parent-id string The ID of the branch parent, default is cluster id. + -c, --cluster-id string The ID of the cluster, in which the branch will be created. + -n, --display-name string The displayName of the branch to be created. + -h, --help help for create + --parent-id string The ID of the branch parent, default is cluster id. + --parent-timestamp string The timestamp of the parent branch, default is current time. (RFC3339 format, e.g., 2024-01-01T00:00:00Z) ``` ### Options inherited from parent commands