refactor!: migrate to urfave/cli v1

Better flexible flags handling.
This commit is contained in:
2022-01-18 14:13:20 +01:00
parent c6db9ee355
commit 0e688f1407
48 changed files with 502 additions and 405 deletions

View File

@ -1,6 +1,7 @@
package record
import (
"context"
"fmt"
"strconv"
@ -9,18 +10,21 @@ import (
"coopcloud.tech/abra/pkg/formatter"
"github.com/libdns/gandi"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"github.com/urfave/cli"
)
// RecordListCommand lists domains.
var RecordListCommand = &cli.Command{
var RecordListCommand = cli.Command{
Name: "list",
Usage: "List domain name records",
Aliases: []string{"ls"},
ArgsUsage: "<zone>",
Flags: []cli.Flag{
internal.DebugFlag,
internal.NoInputFlag,
internal.DNSProviderFlag,
},
Before: internal.SubCommandBefore,
Description: `
This command lists all domain name records managed by a 3rd party provider for
a specific zone.
@ -49,7 +53,7 @@ are listed. This zone must already be created on your provider account.
logrus.Fatalf("%s is not a supported DNS provider", internal.DNSProvider)
}
records, err := provider.GetRecords(c.Context, zone)
records, err := provider.GetRecords(context.Background(), zone)
if err != nil {
logrus.Fatal(err)
}

View File

@ -1,6 +1,7 @@
package record
import (
"context"
"fmt"
"strconv"
@ -11,16 +12,18 @@ import (
"github.com/libdns/gandi"
"github.com/libdns/libdns"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"github.com/urfave/cli"
)
// RecordNewCommand creates a new domain name record.
var RecordNewCommand = &cli.Command{
var RecordNewCommand = cli.Command{
Name: "new",
Usage: "Create a new domain record",
Aliases: []string{"n"},
ArgsUsage: "<zone>",
Flags: []cli.Flag{
internal.DebugFlag,
internal.NoInputFlag,
internal.DNSProviderFlag,
internal.DNSTypeFlag,
internal.DNSNameFlag,
@ -29,6 +32,7 @@ var RecordNewCommand = &cli.Command{
internal.DNSPriorityFlag,
internal.AutoDNSRecordFlag,
},
Before: internal.SubCommandBefore,
Description: `
This command creates a new domain name record for a specific zone.
@ -118,7 +122,7 @@ You may also invoke this command in "wizard" mode and be prompted for input
record.Priority = internal.DNSPriority
}
records, err := provider.GetRecords(c.Context, zone)
records, err := provider.GetRecords(context.Background(), zone)
if err != nil {
logrus.Fatal(err)
}
@ -132,7 +136,7 @@ You may also invoke this command in "wizard" mode and be prompted for input
}
createdRecords, err := provider.SetRecords(
c.Context,
context.Background(),
zone,
[]libdns.Record{record},
)
@ -196,7 +200,7 @@ func autoConfigure(c *cli.Context, provider *gandi.Provider, zone, ipv4 string)
table := formatter.CreateTable(tableCol)
for _, record := range records {
existingRecords, err := provider.GetRecords(c.Context, zone)
existingRecords, err := provider.GetRecords(context.Background(), zone)
if err != nil {
return err
}
@ -216,7 +220,7 @@ func autoConfigure(c *cli.Context, provider *gandi.Provider, zone, ipv4 string)
}
createdRecords, err := provider.SetRecords(
c.Context,
context.Background(),
zone,
[]libdns.Record{record},
)

View File

@ -1,11 +1,11 @@
package record
import (
"github.com/urfave/cli/v2"
"github.com/urfave/cli"
)
// RecordCommand supports managing DNS entries.
var RecordCommand = &cli.Command{
var RecordCommand = cli.Command{
Name: "record",
Usage: "Manage domain name records",
Aliases: []string{"rc"},
@ -30,7 +30,7 @@ to implement new provider support easily.
https://pkg.go.dev/github.com/libdns/libdns
`,
Subcommands: []*cli.Command{
Subcommands: []cli.Command{
RecordListCommand,
RecordNewCommand,
RecordRemoveCommand,

View File

@ -1,6 +1,7 @@
package record
import (
"context"
"fmt"
"strconv"
@ -11,20 +12,23 @@ import (
"github.com/libdns/gandi"
"github.com/libdns/libdns"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"github.com/urfave/cli"
)
// RecordRemoveCommand lists domains.
var RecordRemoveCommand = &cli.Command{
var RecordRemoveCommand = cli.Command{
Name: "remove",
Usage: "Remove a domain name record",
Aliases: []string{"rm"},
ArgsUsage: "<zone>",
Flags: []cli.Flag{
internal.DebugFlag,
internal.NoInputFlag,
internal.DNSProviderFlag,
internal.DNSTypeFlag,
internal.DNSNameFlag,
},
Before: internal.SubCommandBefore,
Description: `
This command removes a domain name record for a specific zone.
@ -70,7 +74,7 @@ You may also invoke this command in "wizard" mode and be prompted for input
logrus.Fatal(err)
}
records, err := provider.GetRecords(c.Context, zone)
records, err := provider.GetRecords(context.Background(), zone)
if err != nil {
logrus.Fatal(err)
}
@ -120,7 +124,7 @@ You may also invoke this command in "wizard" mode and be prompted for input
}
}
_, err = provider.DeleteRecords(c.Context, zone, []libdns.Record{toDelete})
_, err = provider.DeleteRecords(context.Background(), zone, []libdns.Record{toDelete})
if err != nil {
logrus.Fatal(err)
}