diff --git a/cmd/cmd.go b/cmd/cmd.go index 4d4dd3afad..d585a6c81e 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -5,6 +5,7 @@ import "github.com/urfave/cli/v2" // CreateCommands Creates all CLI commands. func CreateCommands() []*cli.Command { return []*cli.Command{ + createRegister(), createRun(), createRevoke(), createRenew(), diff --git a/cmd/cmd_register.go b/cmd/cmd_register.go new file mode 100644 index 0000000000..f5d537ecae --- /dev/null +++ b/cmd/cmd_register.go @@ -0,0 +1,44 @@ +package cmd + +import ( + "fmt" + + "github.com/go-acme/lego/v4/log" + "github.com/urfave/cli/v2" +) + +func createRegister() *cli.Command { + return &cli.Command{ + Name: "register", + Usage: "Register an account", + Before: func(ctx *cli.Context) error { + return nil + }, + Action: registerAction, + Flags: []cli.Flag{}, + } +} + +func registerAction(ctx *cli.Context) error { + accountsStorage := NewAccountsStorage(ctx) + + account, client := setup(ctx, accountsStorage) + setupChallenges(ctx, client) + + if account.Registration == nil { + reg, err := register(ctx, client) + if err != nil { + log.Fatalf("Could not complete registration\n\t%v", err) + } + + account.Registration = reg + if err = accountsStorage.Save(account); err != nil { + log.Fatal(err) + } + + fmt.Printf(rootPathWarningMessage, accountsStorage.GetRootPath()) + return err + } + + return nil +} diff --git a/cmd/cmd_run.go b/cmd/cmd_run.go index 38df4bc5cf..f10ae39074 100644 --- a/cmd/cmd_run.go +++ b/cmd/cmd_run.go @@ -17,7 +17,7 @@ import ( func createRun() *cli.Command { return &cli.Command{ Name: "run", - Usage: "Register an account, then create and install a certificate", + Usage: "Register an account (if not registered), then create and install a certificate", Before: func(ctx *cli.Context) error { // we require either domains or csr, but not both hasDomains := len(ctx.StringSlice("domains")) > 0