2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 07:57:21 +08:00

feat: 添加CLI命令

This commit is contained in:
耗子
2024-11-26 04:06:04 +08:00
parent c1580afadf
commit ff67ace165
2 changed files with 82 additions and 16 deletions

View File

@@ -173,6 +173,51 @@ func Cli() []*cli.Command {
},
},
},
{
Name: "database",
Usage: "数据库管理",
Commands: []*cli.Command{
{
Name: "add-server",
Usage: "添加数据库服务器",
Action: cliService.DatabaseAddServer,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "type",
Usage: "服务器类型",
Required: true,
},
&cli.StringFlag{
Name: "name",
Usage: "服务器名称",
Required: true,
},
&cli.StringFlag{
Name: "host",
Usage: "服务器地址",
Required: true,
},
&cli.UintFlag{
Name: "port",
Usage: "服务器端口",
Required: true,
},
&cli.StringFlag{
Name: "username",
Usage: "服务器用户名",
},
&cli.StringFlag{
Name: "password",
Usage: "服务器密码",
},
&cli.StringFlag{
Name: "remark",
Usage: "服务器备注",
},
},
},
},
},
{
Name: "backup",
Usage: "数据备份",

View File

@@ -31,26 +31,28 @@ import (
)
type CliService struct {
hr string
api *api.API
appRepo biz.AppRepo
userRepo biz.UserRepo
settingRepo biz.SettingRepo
backupRepo biz.BackupRepo
websiteRepo biz.WebsiteRepo
hash hash.Hasher
hr string
api *api.API
appRepo biz.AppRepo
userRepo biz.UserRepo
settingRepo biz.SettingRepo
backupRepo biz.BackupRepo
websiteRepo biz.WebsiteRepo
databaseServerRepo biz.DatabaseServerRepo
hash hash.Hasher
}
func NewCliService() *CliService {
return &CliService{
hr: `+----------------------------------------------------`,
api: api.NewAPI(app.Version),
appRepo: data.NewAppRepo(),
userRepo: data.NewUserRepo(),
settingRepo: data.NewSettingRepo(),
backupRepo: data.NewBackupRepo(),
websiteRepo: data.NewWebsiteRepo(),
hash: hash.NewArgon2id(),
hr: `+----------------------------------------------------`,
api: api.NewAPI(app.Version),
appRepo: data.NewAppRepo(),
userRepo: data.NewUserRepo(),
settingRepo: data.NewSettingRepo(),
backupRepo: data.NewBackupRepo(),
websiteRepo: data.NewWebsiteRepo(),
databaseServerRepo: data.NewDatabaseServerRepo(),
hash: hash.NewArgon2id(),
}
}
@@ -479,6 +481,25 @@ func (s *CliService) WebsiteWrite(ctx context.Context, cmd *cli.Command) error {
return nil
}
func (s *CliService) DatabaseAddServer(ctx context.Context, cmd *cli.Command) error {
req := &request.DatabaseServerCreate{
Type: cmd.String("type"),
Name: cmd.String("name"),
Host: cmd.String("host"),
Port: uint(cmd.Uint("port")),
Username: cmd.String("username"),
Password: cmd.String("password"),
Remark: cmd.String("remark"),
}
if err := s.databaseServerRepo.Create(req); err != nil {
return err
}
fmt.Printf("数据库服务器 %s 添加成功\n", cmd.String("name"))
return nil
}
func (s *CliService) BackupWebsite(ctx context.Context, cmd *cli.Command) error {
fmt.Println(s.hr)
fmt.Printf("★ 开始备份 [%s]\n", time.Now().Format(time.DateTime))