Skip to content

Commit c808038

Browse files
committed
chore: migrate to urfave v3
1 parent 24a46d0 commit c808038

File tree

19 files changed

+402
-391
lines changed

19 files changed

+402
-391
lines changed

cmd/accounts_storage.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/go-acme/lego/v4/lego"
1616
"github.com/go-acme/lego/v4/log"
1717
"github.com/go-acme/lego/v4/registration"
18-
"github.com/urfave/cli/v2"
18+
"github.com/urfave/cli/v3"
1919
)
2020

2121
const (
@@ -63,20 +63,20 @@ type AccountsStorage struct {
6363
rootUserPath string
6464
keysPath string
6565
accountFilePath string
66-
ctx *cli.Context
66+
cmd *cli.Command
6767
}
6868

6969
// NewAccountsStorage Creates a new AccountsStorage.
70-
func NewAccountsStorage(ctx *cli.Context) *AccountsStorage {
70+
func NewAccountsStorage(cmd *cli.Command) *AccountsStorage {
7171
// TODO: move to account struct? Currently MUST pass email.
72-
email := getEmail(ctx)
72+
email := getEmail(cmd)
7373

74-
serverURL, err := url.Parse(ctx.String(flgServer))
74+
serverURL, err := url.Parse(cmd.String(flgServer))
7575
if err != nil {
7676
log.Fatal(err)
7777
}
7878

79-
rootPath := filepath.Join(ctx.String(flgPath), baseAccountsRootFolderName)
79+
rootPath := filepath.Join(cmd.String(flgPath), baseAccountsRootFolderName)
8080
serverPath := strings.NewReplacer(":", "_", "/", string(os.PathSeparator)).Replace(serverURL.Host)
8181
accountsPath := filepath.Join(rootPath, serverPath)
8282
rootUserPath := filepath.Join(accountsPath, email)
@@ -87,7 +87,7 @@ func NewAccountsStorage(ctx *cli.Context) *AccountsStorage {
8787
rootUserPath: rootUserPath,
8888
keysPath: filepath.Join(rootUserPath, baseKeysFolderName),
8989
accountFilePath: filepath.Join(rootUserPath, accountFileName),
90-
ctx: ctx,
90+
cmd: cmd,
9191
}
9292
}
9393

@@ -137,7 +137,7 @@ func (s *AccountsStorage) LoadAccount(privateKey crypto.PrivateKey) *Account {
137137
account.key = privateKey
138138

139139
if account.Registration == nil || account.Registration.Body.Status == "" {
140-
reg, err := tryRecoverRegistration(s.ctx, privateKey)
140+
reg, err := tryRecoverRegistration(s.cmd, privateKey)
141141
if err != nil {
142142
log.Fatalf("Could not load account for %s. Registration is nil: %#v", s.userID, err)
143143
}
@@ -221,11 +221,11 @@ func loadPrivateKey(file string) (crypto.PrivateKey, error) {
221221
return nil, errors.New("unknown private key type")
222222
}
223223

224-
func tryRecoverRegistration(ctx *cli.Context, privateKey crypto.PrivateKey) (*registration.Resource, error) {
224+
func tryRecoverRegistration(cmd *cli.Command, privateKey crypto.PrivateKey) (*registration.Resource, error) {
225225
// couldn't load account but got a key. Try to look the account up.
226226
config := lego.NewConfig(&Account{key: privateKey})
227-
config.CADirURL = ctx.String(flgServer)
228-
config.UserAgent = getUserAgent(ctx)
227+
config.CADirURL = cmd.String(flgServer)
228+
config.UserAgent = getUserAgent(cmd)
229229

230230
client, err := lego.NewClient(config)
231231
if err != nil {

cmd/certs_storage.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/go-acme/lego/v4/certcrypto"
1818
"github.com/go-acme/lego/v4/certificate"
1919
"github.com/go-acme/lego/v4/log"
20-
"github.com/urfave/cli/v2"
20+
"github.com/urfave/cli/v3"
2121
"golang.org/x/net/idna"
2222
"software.sslmate.com/src/go-pkcs12"
2323
)
@@ -60,8 +60,8 @@ type CertificatesStorage struct {
6060
}
6161

6262
// NewCertificatesStorage create a new certificates storage.
63-
func NewCertificatesStorage(ctx *cli.Context) *CertificatesStorage {
64-
pfxFormat := ctx.String(flgPFXFormat)
63+
func NewCertificatesStorage(cmd *cli.Command) *CertificatesStorage {
64+
pfxFormat := cmd.String(flgPFXFormat)
6565

6666
switch pfxFormat {
6767
case "DES", "RC2", "SHA256":
@@ -70,13 +70,13 @@ func NewCertificatesStorage(ctx *cli.Context) *CertificatesStorage {
7070
}
7171

7272
return &CertificatesStorage{
73-
rootPath: filepath.Join(ctx.String(flgPath), baseCertificatesFolderName),
74-
archivePath: filepath.Join(ctx.String(flgPath), baseArchivesFolderName),
75-
pem: ctx.Bool(flgPEM),
76-
pfx: ctx.Bool(flgPFX),
77-
pfxPassword: ctx.String(flgPFXPass),
73+
rootPath: filepath.Join(cmd.String(flgPath), baseCertificatesFolderName),
74+
archivePath: filepath.Join(cmd.String(flgPath), baseArchivesFolderName),
75+
pem: cmd.Bool(flgPEM),
76+
pfx: cmd.Bool(flgPFX),
77+
pfxPassword: cmd.String(flgPFXPass),
7878
pfxFormat: pfxFormat,
79-
filename: ctx.String(flgFilename),
79+
filename: cmd.String(flgFilename),
8080
}
8181
}
8282

cmd/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cmd
22

3-
import "github.com/urfave/cli/v2"
3+
import "github.com/urfave/cli/v3"
44

55
// CreateCommands Creates all CLI commands.
66
func CreateCommands() []*cli.Command {

cmd/cmd_before.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
package cmd
22

33
import (
4+
"context"
5+
46
"github.com/go-acme/lego/v4/log"
5-
"github.com/urfave/cli/v2"
7+
"github.com/urfave/cli/v3"
68
)
79

8-
func Before(ctx *cli.Context) error {
9-
if ctx.String(flgPath) == "" {
10+
func Before(ctx context.Context, cmd *cli.Command) (context.Context, error) {
11+
if cmd.String(flgPath) == "" {
1012
log.Fatalf("Could not determine current working directory. Please pass --%s.", flgPath)
1113
}
1214

13-
err := createNonExistingFolder(ctx.String(flgPath))
15+
err := createNonExistingFolder(cmd.String(flgPath))
1416
if err != nil {
1517
log.Fatalf("Could not check/create path: %v", err)
1618
}
1719

18-
if ctx.String(flgServer) == "" {
20+
if cmd.String(flgServer) == "" {
1921
log.Fatalf("Could not determine current working server. Please pass --%s.", flgServer)
2022
}
2123

22-
return nil
24+
return ctx, nil
2325
}

cmd/cmd_dnshelp.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package cmd
22

33
import (
4+
"context"
45
"fmt"
56
"io"
67
"strings"
78
"text/tabwriter"
89

9-
"github.com/urfave/cli/v2"
10+
"github.com/urfave/cli/v3"
1011
)
1112

1213
const flgCode = "code"
@@ -26,10 +27,10 @@ func createDNSHelp() *cli.Command {
2627
}
2728
}
2829

29-
func dnsHelp(ctx *cli.Context) error {
30-
code := ctx.String(flgCode)
30+
func dnsHelp(_ context.Context, cmd *cli.Command) error {
31+
code := cmd.String(flgCode)
3132
if code == "" {
32-
w := tabwriter.NewWriter(ctx.App.Writer, 0, 0, 2, ' ', 0)
33+
w := tabwriter.NewWriter(cmd.Writer, 0, 0, 2, ' ', 0)
3334
ew := &errWriter{w: w}
3435

3536
ew.writeln(`Credentials for DNS providers must be passed through environment variables.`)
@@ -50,7 +51,7 @@ func dnsHelp(ctx *cli.Context) error {
5051
return w.Flush()
5152
}
5253

53-
return displayDNSHelp(ctx.App.Writer, strings.ToLower(code))
54+
return displayDNSHelp(cmd.Writer, strings.ToLower(code))
5455
}
5556

5657
type errWriter struct {

cmd/cmd_list.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
67
"net/url"
@@ -9,7 +10,7 @@ import (
910
"strings"
1011

1112
"github.com/go-acme/lego/v4/certcrypto"
12-
"github.com/urfave/cli/v2"
13+
"github.com/urfave/cli/v3"
1314
)
1415

1516
const (
@@ -43,25 +44,25 @@ func createList() *cli.Command {
4344
}
4445
}
4546

46-
func list(ctx *cli.Context) error {
47-
if ctx.Bool(flgAccounts) && !ctx.Bool(flgNames) {
48-
if err := listAccount(ctx); err != nil {
47+
func list(ctx context.Context, cmd *cli.Command) error {
48+
if cmd.Bool(flgAccounts) && !cmd.Bool(flgNames) {
49+
if err := listAccount(ctx, cmd); err != nil {
4950
return err
5051
}
5152
}
5253

53-
return listCertificates(ctx)
54+
return listCertificates(ctx, cmd)
5455
}
5556

56-
func listCertificates(ctx *cli.Context) error {
57-
certsStorage := NewCertificatesStorage(ctx)
57+
func listCertificates(_ context.Context, cmd *cli.Command) error {
58+
certsStorage := NewCertificatesStorage(cmd)
5859

5960
matches, err := filepath.Glob(filepath.Join(certsStorage.GetRootPath(), "*.crt"))
6061
if err != nil {
6162
return err
6263
}
6364

64-
names := ctx.Bool(flgNames)
65+
names := cmd.Bool(flgNames)
6566

6667
if len(matches) == 0 {
6768
if !names {
@@ -108,8 +109,8 @@ func listCertificates(ctx *cli.Context) error {
108109
return nil
109110
}
110111

111-
func listAccount(ctx *cli.Context) error {
112-
accountsStorage := NewAccountsStorage(ctx)
112+
func listAccount(_ context.Context, cmd *cli.Command) error {
113+
accountsStorage := NewAccountsStorage(cmd)
113114

114115
matches, err := filepath.Glob(filepath.Join(accountsStorage.GetRootPath(), "*", "*", "*.json"))
115116
if err != nil {

0 commit comments

Comments
 (0)