photoprism/internal/commands/connect.go
Michael Mayer cd4e6f1b57 CLI: Add RunWithTestContext function for command tests #3168
Signed-off-by: Michael Mayer <michael@photoprism.app>
2024-12-06 09:08:38 +01:00

36 lines
820 B
Go

package commands
import (
"github.com/urfave/cli/v2"
"github.com/photoprism/photoprism/internal/config"
)
// ConnectCommand configures the command name, flags, and action.
var ConnectCommand = &cli.Command{
Name: "connect",
Usage: "Connects your membership account",
ArgsUsage: "[activation code]",
Action: connectAction,
}
// connectAction connects your membership account.
func connectAction(ctx *cli.Context) error {
return CallWithDependencies(ctx, func(conf *config.Config) error {
token := ctx.Args().First()
// Fail if no code was provided.
if token == "" {
return cli.ShowSubcommandHelp(ctx)
}
// Renew API keys with token.
if err := conf.RenewApiKeysWithToken(token); err != nil {
return err
}
log.Infof("successfully connected your account")
return nil
})
}