Skip to content

Commit

Permalink
chore: correct grammar and regular expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
lizzy-0323 committed Sep 30, 2024
1 parent 017db36 commit 038fd9e
Show file tree
Hide file tree
Showing 17 changed files with 27 additions and 37 deletions.
2 changes: 1 addition & 1 deletion internal/cli/cmd/cluster/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewDeleteCmd() *cobra.Command {
if err != nil {
logger.Fatalln(err)
}
logger.Printf("Delete ob cluster %s success", o.Name)
logger.Printf("Delete ob cluster %s successfully", o.Name)
},
}
o.AddFlags(cmd)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cmd/cluster/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewScaleCmd() *cobra.Command {
if _, err = clients.CreateOBClusterOperation(cmd.Context(), op); err != nil {
logger.Fatalln(err)
}
logger.Printf("Create scale operation for obcluster %s success", op.Spec.OBCluster)
logger.Printf("Create scale operation for obcluster %s successfully", op.Spec.OBCluster)
},
}
o.AddFlags(cmd)
Expand Down
10 changes: 5 additions & 5 deletions internal/cli/cmd/cluster/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewShowCmd() *cobra.Command {
if err != nil {
logger.Fatalln(err)
}
obclusterOperation, err := clients.GetOBClusterOperations(cmd.Context(), obcluster)
obclusterOperationList, err := clients.GetOBClusterOperations(cmd.Context(), obcluster)
if err != nil {
logger.Fatalln(err)
}
Expand All @@ -57,12 +57,12 @@ func NewShowCmd() *cobra.Command {
}
}

if len(obclusterOperation.Items) > 0 {
sort.Slice(obclusterOperation.Items, func(i, j int) bool {
return obclusterOperation.Items[i].Name < obclusterOperation.Items[j].Name
if len(obclusterOperationList.Items) > 0 {
sort.Slice(obclusterOperationList.Items, func(i, j int) bool {
return obclusterOperationList.Items[i].Name < obclusterOperationList.Items[j].Name
})
tbLog.Println("OPERATION TYPE \t TTLDAYS \t STATUS \t CREATETIME")
for _, op := range obclusterOperation.Items {
for _, op := range obclusterOperationList.Items {
tbLog.Printf("%s \t %d \t %s \t %s\n", op.Spec.Type, op.Spec.TTLDays, op.Status.Status, op.CreationTimestamp)
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cmd/cluster/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewUpdateCmd() *cobra.Command {
if _, err = clients.CreateOBClusterOperation(cmd.Context(), op); err != nil {
logger.Fatalln(err)
}
logger.Printf("Create update operation for obcluster %s success", op.Spec.OBCluster)
logger.Printf("Create update operation for obcluster %s successfully", op.Spec.OBCluster)
},
}
o.AddFlags(cmd)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cmd/cluster/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewUpgradeCmd() *cobra.Command {
if _, err = clients.CreateOBClusterOperation(cmd.Context(), op); err != nil {
logger.Fatalln(err)
}
logger.Printf("Create upgrade operation for obcluster %s success", op.Spec.OBCluster)
logger.Printf("Create upgrade operation for obcluster %s successfully", op.Spec.OBCluster)
},
}
o.AddFlags(cmd)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cmd/tenant/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewActivateCmd() *cobra.Command {
if _, err = clients.CreateOBTenantOperation(cmd.Context(), op); err != nil {
logger.Fatalln(err)
}
logger.Printf("Create activate operation for tenant %s success", o.Name)
logger.Printf("Create activate operation for tenant %s successfully", o.Name)
},
}
o.AddFlags(cmd)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cmd/tenant/changepwd.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewChangePwdCmd() *cobra.Command {
if _, err = clients.CreateOBTenantOperation(cmd.Context(), op); err != nil {
logger.Fatalln(err)
}
logger.Printf("Create changepwd operation for obtenant %s success", o.Name)
logger.Printf("Create changepwd operation for obtenant %s successfully", o.Name)
},
}
o.AddFlags(cmd)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cmd/tenant/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewDeleteCmd() *cobra.Command {
if err != nil {
logger.Fatalln(err)
}
logger.Printf("Delete ob tenant %s success", o.Name)
logger.Printf("Delete ob tenant %s successfully", o.Name)
},
}
o.AddFlags(cmd)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cmd/tenant/replaylog.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewReplayLogCmd() *cobra.Command {
if _, err = clients.CreateOBTenantOperation(cmd.Context(), op); err != nil {
logger.Fatalln(err)
}
logger.Printf("Create replay log operation of tenant %s success", o.Name)
logger.Printf("Create replay log operation of tenant %s successfully", o.Name)
},
}
o.AddFlags(cmd)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cmd/tenant/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewScaleCmd() *cobra.Command {
if _, err = clients.CreateOBTenantOperation(cmd.Context(), op); err != nil {
logger.Fatalln(err)
}
logger.Printf("Create scale operation for obtenant %s success", o.Name)
logger.Printf("Create scale operation for obtenant %s successfully", o.Name)
},
}
o.AddFlags(cmd)
Expand Down
10 changes: 5 additions & 5 deletions internal/cli/cmd/tenant/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewShowCmd() *cobra.Command {
if err != nil {
logger.Fatalln(err)
}
obtenantOperation, err := clients.GetOBTenantOperations(cmd.Context(), obtenant)
obtenantOperationList, err := clients.GetOBTenantOperations(cmd.Context(), obtenant)
if err != nil {
logger.Fatalln(err)
}
Expand All @@ -54,12 +54,12 @@ func NewShowCmd() *cobra.Command {
tbLog.Printf("%s \t %d \t %d\n\n", pool.ZoneList, pool.UnitNumber, pool.Priority)
}
}
if len(obtenantOperation.Items) > 0 {
sort.Slice(obtenantOperation.Items, func(i, j int) bool {
return obtenantOperation.Items[i].Name < obtenantOperation.Items[j].Name
if len(obtenantOperationList.Items) > 0 {
sort.Slice(obtenantOperationList.Items, func(i, j int) bool {
return obtenantOperationList.Items[i].Name < obtenantOperationList.Items[j].Name
})
tbLog.Println("OPERATION TYPE \t STATUS \t CREATETIME")
for _, op := range obtenantOperation.Items {
for _, op := range obtenantOperationList.Items {
tbLog.Printf("%s \t %s \t %s\n", op.Spec.Type, op.Status.Status, op.CreationTimestamp)
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cmd/tenant/switchover.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewSwitchOverCmd() *cobra.Command {
if _, err := clients.CreateOBTenantOperation(cmd.Context(), op); err != nil {
logger.Fatalln(err)
}
logger.Printf("Create switchover operation for primary tenant %s and standby tenant %s success", o.PrimaryTenant, o.StandbyTenant)
logger.Printf("Create switchover operation for primary tenant %s and standby tenant %s successfully", o.PrimaryTenant, o.StandbyTenant)
},
}
o.AddFlags(cmd)
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/cmd/tenant/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewUpdateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "update <tenant_name>",
Short: "Update ob tenant",
Long: "Update ob tenant, support unitNumber/charset/connectWhiteList/priority of zones",
Long: "Update ob tenant, support unitNumber/connectWhiteList/priority of zones",
Args: cobra.ExactArgs(1),
Aliases: []string{"ud"},
PreRunE: o.Parse,
Expand All @@ -56,7 +56,7 @@ func NewUpdateCmd() *cobra.Command {
if _, err = clients.CreateOBTenantOperation(cmd.Context(), op); err != nil {
logger.Fatalln(err)
}
logger.Printf("Create update operation for obtenant %s success", o.Name)
logger.Printf("Create update operation for obtenant %s successfully", o.Name)
},
}
o.AddFlags(cmd)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cmd/tenant/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewUpgradeCmd() *cobra.Command {
if _, err = clients.CreateOBTenantOperation(cmd.Context(), op); err != nil {
logger.Fatalln(err)
}
logger.Printf("Create upgrade operation for obtenant %s success", o.Name)
logger.Printf("Create upgrade operation for obtenant %s successfully", o.Name)
},
}
o.AddFlags(cmd)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/tenant/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewActivateOptions() *ActivateOptions {
func GetActivateOperation(o *ActivateOptions) *v1alpha1.OBTenantOperation {
activateOp := &v1alpha1.OBTenantOperation{
ObjectMeta: v1.ObjectMeta{
Name: o.Name + "-change-role-" + rand.String(6),
Name: o.Name + "-activate-" + rand.String(6),
Namespace: o.Namespace,
Labels: map[string]string{oceanbaseconst.LabelRefOBTenantOp: o.Name},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/tenant/switchover.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (o *SwitchOverOptions) Parse(_ *cobra.Command, args []string) error {
func GetSwitchOverOperation(o *SwitchOverOptions) *v1alpha1.OBTenantOperation {
switchOverOp := &v1alpha1.OBTenantOperation{
ObjectMeta: v1.ObjectMeta{
Name: o.PrimaryTenant + "-change-role-" + rand.String(6),
Name: o.PrimaryTenant + "-switchover-" + rand.String(6),
Namespace: o.Namespace,
Labels: map[string]string{oceanbaseconst.LabelRefOBTenantOp: o.PrimaryTenant},
},
Expand Down
14 changes: 2 additions & 12 deletions internal/cli/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ func GenerateClusterID() int64 {
// CheckResourceName checks resource name in k8s
func CheckResourceName(name string) bool {
regex := `[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*`

re, err := regexp.Compile(regex)
if err != nil {
panic("error when compiling regex expressions")
}

re := regexp.MustCompile(regex)
return re.MatchString(name)
}

Expand Down Expand Up @@ -104,12 +99,7 @@ func CheckPassword(password string) bool {
// CheckTenantName check Tenant name when creating tenant
func CheckTenantName(name string) bool {
regex := `^[_a-zA-Z][^-]*$`

re, err := regexp.Compile(regex)
if err != nil {
panic("error when compiling regex expressions")
}

re := regexp.MustCompile(regex)
return re.MatchString(name)
}

Expand Down

0 comments on commit 038fd9e

Please sign in to comment.