GeezerVison is showing github.com — refactor(udns): restructure to internal/udns per onboarding spec · ucloud/ucloud-cli@6693084
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: cmd/products.gen.go +2Lines changed: 2 additions & 0 deletions Collapse file Copy file name to clipboardExpand all lines: products/udns/internal/udns/associate_vpc.go -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,7 +10,6 @@ import ( | 10 | 10 | "github.com/ucloud/ucloud-cli/pkg/cli" | 11 | 11 | ) | 12 | 12 |
| 13 | | -// newAssociateVPCCommand builds `udns associate-vpc` (AssociateUDNSZoneVPC). | 14 | 13 | func newAssociateVPCCommand(ctx *cli.Context) *cobra.Command { | 15 | 14 | client := cli.NewServiceClient(ctx, udnssdk.NewClient) | 16 | 15 | req := client.NewAssociateUDNSZoneVPCRequest() | |
Collapse file Copy file name to clipboard +22Lines changed: 22 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +package udns | | 2 | + | | 3 | +import ( | | 4 | + "github.com/spf13/cobra" | | 5 | + | | 6 | + "github.com/ucloud/ucloud-cli/pkg/cli" | | 7 | +) | | 8 | + | | 9 | +func NewCommand(ctx *cli.Context) *cobra.Command { | | 10 | + root := &cobra.Command{ | | 11 | + Use: "udns", | | 12 | + Short: "List and manipulate ucloud private dns(udns) instance and record", | | 13 | + Long: "List and manipulate ucloud private dns(udns) instance and record", | | 14 | + } | | 15 | + root.AddCommand(newCreateCommand(ctx)) | | 16 | + root.AddCommand(newListCommand(ctx)) | | 17 | + root.AddCommand(newModifyCommand(ctx)) | | 18 | + root.AddCommand(newAssociateVPCCommand(ctx)) | | 19 | + root.AddCommand(newDisassociateVPCCommand(ctx)) | | 20 | + root.AddCommand(newRecordCommand(ctx)) | | 21 | + return root | | 22 | +} |
Collapse file Copy file name to clipboardExpand all lines: products/udns/internal/udns/create.go +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,10 +8,10 @@ import ( | 8 | 8 | udnssdk "github.com/ucloud/ucloud-sdk-go/services/udns" | 9 | 9 |
| 10 | 10 | "github.com/ucloud/ucloud-cli/pkg/cli" | | 11 | + "github.com/ucloud/ucloud-cli/pkg/command" | 11 | 12 | ) | 12 | 13 |
| 13 | | -// NewCreateCommand builds `udns create` (CreateUDNSZone). | 14 | | -func NewCreateCommand(ctx *cli.Context) *cobra.Command { | | 14 | +func newCreateCommand(ctx *cli.Context) *cobra.Command { | 15 | 15 | client := cli.NewServiceClient(ctx, udnssdk.NewClient) | 16 | 16 | req := client.NewCreateUDNSZoneRequest() | 17 | 17 | cmd := &cobra.Command{ | @@ -39,9 +39,9 @@ func NewCreateCommand(ctx *cli.Context) *cobra.Command { | 39 | 39 | req.Remark = flags.String("remark", "", "Optional. Remark") | 40 | 40 | ctx.BindRegion(cmd, req) | 41 | 41 | ctx.BindProjectID(cmd, req) | 42 | | - ctx.SetFlagValues(cmd, "type", "private", "public") | 43 | | - ctx.SetFlagValues(cmd, "charge-type", "Month", "Year", "Dynamic") | 44 | | - ctx.SetFlagValues(cmd, "recursion", "enable", "disable") | | 42 | + command.SetFlagValues(cmd, "type", "private", "public") | | 43 | + command.SetFlagValues(cmd, "charge-type", "Month", "Year", "Dynamic") | | 44 | + command.SetFlagValues(cmd, "recursion", "enable", "disable") | 45 | 45 | cmd.MarkFlagRequired("zone-name") | 46 | 46 | cmd.MarkFlagRequired("type") | 47 | 47 | return cmd | |
Collapse file Copy file name to clipboardExpand all lines: products/udns/internal/udns/disassociate_vpc.go -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,7 +10,6 @@ import ( | 10 | 10 | "github.com/ucloud/ucloud-cli/pkg/cli" | 11 | 11 | ) | 12 | 12 |
| 13 | | -// newDisassociateVPCCommand builds `udns disassociate-vpc` (DisassociateUDNSZoneVPC). | 14 | 13 | func newDisassociateVPCCommand(ctx *cli.Context) *cobra.Command { | 15 | 14 | client := cli.NewServiceClient(ctx, udnssdk.NewClient) | 16 | 15 | req := client.NewDisassociateUDNSZoneVPCRequest() | |
Collapse file Copy file name to clipboardExpand all lines: products/udns/internal/udns/list.go +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,7 +11,6 @@ import ( | 11 | 11 | "github.com/ucloud/ucloud-cli/pkg/cli" | 12 | 12 | ) | 13 | 13 |
| 14 | | -// newListCommand builds `udns list` (DescribeUDNSZone). | 15 | 14 | func newListCommand(ctx *cli.Context) *cobra.Command { | 16 | 15 | client := cli.NewServiceClient(ctx, udnssdk.NewClient) | 17 | 16 | req := client.NewDescribeUDNSZoneRequest() | @@ -27,7 +26,7 @@ func newListCommand(ctx *cli.Context) *cobra.Command { | 27 | 26 | ctx.HandleError(err) | 28 | 27 | return | 29 | 28 | } | 30 | | - rows := make([]ZoneRow, 0, len(resp.DNSZoneInfos)) | | 29 | + rows := make([]zoneRow, 0, len(resp.DNSZoneInfos)) | 31 | 30 | for _, z := range resp.DNSZoneInfos { | 32 | 31 | rows = append(rows, toZoneRow(z)) | 33 | 32 | } | @@ -44,12 +43,12 @@ func newListCommand(ctx *cli.Context) *cobra.Command { | 44 | 43 | return cmd | 45 | 44 | } | 46 | 45 |
| 47 | | -func toZoneRow(z udnssdk.ZoneInfo) ZoneRow { | | 46 | +func toZoneRow(z udnssdk.ZoneInfo) zoneRow { | 48 | 47 | vpcIDs := make([]string, 0, len(z.VPCInfos)) | 49 | 48 | for _, v := range z.VPCInfos { | 50 | 49 | vpcIDs = append(vpcIDs, v.VPCId) | 51 | 50 | } | 52 | | - return ZoneRow{ | | 51 | + return zoneRow{ | 53 | 52 | ZoneID: z.DNSZoneId, | 54 | 53 | Name: z.DNSZoneName, | 55 | 54 | ChargeType: z.ChargeType, | |
Collapse file Copy file name to clipboardExpand all lines: products/udns/internal/udns/modify.go +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | udnssdk "github.com/ucloud/ucloud-sdk-go/services/udns" | 9 | 9 |
| 10 | 10 | "github.com/ucloud/ucloud-cli/pkg/cli" | | 11 | + "github.com/ucloud/ucloud-cli/pkg/command" | 11 | 12 | ) | 12 | 13 |
| 13 | | -// newModifyCommand builds `udns modify` (ModifyUDNSZone). | 14 | 14 | func newModifyCommand(ctx *cli.Context) *cobra.Command { | 15 | 15 | client := cli.NewServiceClient(ctx, udnssdk.NewClient) | 16 | 16 | req := client.NewModifyUDNSZoneRequest() | @@ -37,7 +37,7 @@ func newModifyCommand(ctx *cli.Context) *cobra.Command { | 37 | 37 | req.Remark = flags.String("remark", "", "Optional. Remark") | 38 | 38 | ctx.BindRegion(cmd, req) | 39 | 39 | ctx.BindProjectID(cmd, req) | 40 | | - ctx.SetFlagValues(cmd, "recursion", "enable", "disable") | | 40 | + command.SetFlagValues(cmd, "recursion", "enable", "disable") | 41 | 41 | cmd.MarkFlagRequired("zone-id") | 42 | 42 | return cmd | 43 | 43 | } |
Collapse file Copy file name to clipboardExpand all lines: products/udns/internal/udns/record.go -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | "github.com/ucloud/ucloud-cli/pkg/cli" | 7 | 7 | ) | 8 | 8 |
| 9 | | -// newRecordCommand builds the `udns record` subgroup. | 10 | 9 | func newRecordCommand(ctx *cli.Context) *cobra.Command { | 11 | 10 | cmd := &cobra.Command{ | 12 | 11 | Use: "record", | |
Collapse file Copy file name to clipboardExpand all lines: products/udns/internal/udns/record_create.go +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | udnssdk "github.com/ucloud/ucloud-sdk-go/services/udns" | 9 | 9 |
| 10 | 10 | "github.com/ucloud/ucloud-cli/pkg/cli" | | 11 | + "github.com/ucloud/ucloud-cli/pkg/command" | 11 | 12 | ) | 12 | 13 |
| 13 | | -// newRecordCreateCommand builds `udns record create` (CreateUDNSRecord). | 14 | 14 | func newRecordCreateCommand(ctx *cli.Context) *cobra.Command { | 15 | 15 | client := cli.NewServiceClient(ctx, udnssdk.NewClient) | 16 | 16 | req := client.NewCreateUDNSRecordRequest() | @@ -39,8 +39,8 @@ func newRecordCreateCommand(ctx *cli.Context) *cobra.Command { | 39 | 39 | req.Remark = flags.String("remark", "", "Optional. Remark") | 40 | 40 | ctx.BindRegion(cmd, req) | 41 | 41 | ctx.BindProjectID(cmd, req) | 42 | | - ctx.SetFlagValues(cmd, "type", "A", "AAAA", "CNAME", "MX", "TXT", "SRV", "PTR") | 43 | | - ctx.SetFlagValues(cmd, "value-type", "Normal", "Multivalue") | | 42 | + command.SetFlagValues(cmd, "type", "A", "AAAA", "CNAME", "MX", "TXT", "SRV", "PTR") | | 43 | + command.SetFlagValues(cmd, "value-type", "Normal", "Multivalue") | 44 | 44 | cmd.MarkFlagRequired("zone-id") | 45 | 45 | cmd.MarkFlagRequired("name") | 46 | 46 | cmd.MarkFlagRequired("type") | |
Collapse file Copy file name to clipboardExpand all lines: products/udns/internal/udns/record_delete.go +11-2Lines changed: 11 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,21 +10,29 @@ import ( | 10 | 10 | "github.com/ucloud/ucloud-cli/pkg/cli" | 11 | 11 | ) | 12 | 12 |
| 13 | | -// newRecordDeleteCommand builds `udns record delete` (DeleteUDNSRecord). | 14 | 13 | func newRecordDeleteCommand(ctx *cli.Context) *cobra.Command { | 15 | 14 | client := cli.NewServiceClient(ctx, udnssdk.NewClient) | 16 | 15 | req := client.NewDeleteUDNSRecordRequest() | 17 | 16 | var recordIDs []string | | 17 | + var yes bool | 18 | 18 | cmd := &cobra.Command{ | 19 | 19 | Use: "delete", | 20 | 20 | Short: "Delete DNS records from a UDNS zone", | 21 | 21 | Long: "Delete DNS records from a UDNS zone", | 22 | 22 | Run: func(cmd *cobra.Command, args []string) { | | 23 | + ok, err := ctx.Confirm(yes, "Are you sure you want to delete the record(s)?") | | 24 | + if err != nil { | | 25 | + ctx.HandleError(err) | | 26 | + return | | 27 | + } | | 28 | + if !ok { | | 29 | + return | | 30 | + } | 23 | 31 | for i, id := range recordIDs { | 24 | 32 | recordIDs[i] = ctx.PickResourceID(id) | 25 | 33 | } | 26 | 34 | req.RecordIds = recordIDs | 27 | | - _, err := client.DeleteUDNSRecord(req) | | 35 | + _, err = client.DeleteUDNSRecord(req) | 28 | 36 | if err != nil { | 29 | 37 | ctx.HandleError(err) | 30 | 38 | return | @@ -41,6 +49,7 @@ func newRecordDeleteCommand(ctx *cli.Context) *cobra.Command { | 41 | 49 | flags.SortFlags = false | 42 | 50 | req.DNSZoneId = flags.String("zone-id", "", "Required. Zone resource ID") | 43 | 51 | flags.StringSliceVar(&recordIDs, "record-id", nil, "Required. Record resource ID (repeatable)") | | 52 | + flags.BoolVarP(&yes, "yes", "y", false, "Optional. Skip the confirmation prompt.") | 44 | 53 | ctx.BindRegion(cmd, req) | 45 | 54 | ctx.BindProjectID(cmd, req) | 46 | 55 | cmd.MarkFlagRequired("zone-id") | |
|