mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 03:07:20 +08:00
feat: cli 路由支持
This commit is contained in:
1
go.mod
1
go.mod
@@ -40,6 +40,7 @@ require (
|
||||
github.com/swaggo/http-swagger/v2 v2.0.2
|
||||
github.com/swaggo/swag v1.16.3
|
||||
github.com/urfave/cli/v2 v2.27.4
|
||||
github.com/urfave/cli/v3 v3.0.0-alpha9
|
||||
go.uber.org/zap v1.27.0
|
||||
golang.org/x/crypto v0.27.0
|
||||
golang.org/x/net v0.29.0
|
||||
|
||||
2
go.sum
2
go.sum
@@ -323,6 +323,8 @@ github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
|
||||
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
||||
github.com/urfave/cli/v2 v2.27.4 h1:o1owoI+02Eb+K107p27wEX9Bb8eqIoZCfLXloLUSWJ8=
|
||||
github.com/urfave/cli/v2 v2.27.4/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ=
|
||||
github.com/urfave/cli/v3 v3.0.0-alpha9 h1:P0RMy5fQm1AslQS+XCmy9UknDXctOmG/q/FZkUFnJSo=
|
||||
github.com/urfave/cli/v3 v3.0.0-alpha9/go.mod h1:0kK/RUFHyh+yIKSfWxwheGndfnrvYSmYFVeKCh03ZUc=
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
|
||||
|
||||
@@ -1,26 +1,48 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
|
||||
"github.com/TheTNB/panel/internal/panel"
|
||||
"github.com/TheTNB/panel/internal/route"
|
||||
)
|
||||
|
||||
func initCli() {
|
||||
app := &cli.App{
|
||||
Name: "panel-cli",
|
||||
HelpName: fmt.Sprintf("耗子面板 %s", panel.Version),
|
||||
Usage: "命令行工具",
|
||||
UsageText: "panel-cli [global options] command [command options] [arguments...]",
|
||||
HideVersion: true,
|
||||
Commands: route.Cli(),
|
||||
}
|
||||
cli.RootCommandHelpTemplate = strings.ReplaceAll(cli.RootCommandHelpTemplate, "NAME", "名称")
|
||||
cli.RootCommandHelpTemplate = strings.ReplaceAll(cli.RootCommandHelpTemplate, "USAGE", "用法")
|
||||
cli.RootCommandHelpTemplate = strings.ReplaceAll(cli.RootCommandHelpTemplate, "VERSION", "版本")
|
||||
cli.RootCommandHelpTemplate = strings.ReplaceAll(cli.RootCommandHelpTemplate, "DESCRIPTION", "描述")
|
||||
cli.RootCommandHelpTemplate = strings.ReplaceAll(cli.RootCommandHelpTemplate, "AUTHOR", "作者")
|
||||
cli.RootCommandHelpTemplate = strings.ReplaceAll(cli.RootCommandHelpTemplate, "COMMANDS", "命令")
|
||||
cli.RootCommandHelpTemplate = strings.ReplaceAll(cli.RootCommandHelpTemplate, "GLOBAL OPTIONS", "全局选项")
|
||||
cli.RootCommandHelpTemplate = strings.ReplaceAll(cli.RootCommandHelpTemplate, "COPYRIGHT", "版权")
|
||||
cli.CommandHelpTemplate = strings.ReplaceAll(cli.CommandHelpTemplate, "NAME", "名称")
|
||||
cli.CommandHelpTemplate = strings.ReplaceAll(cli.CommandHelpTemplate, "USAGE", "用法")
|
||||
cli.CommandHelpTemplate = strings.ReplaceAll(cli.CommandHelpTemplate, "CATEGORY", "分类")
|
||||
cli.CommandHelpTemplate = strings.ReplaceAll(cli.CommandHelpTemplate, "DESCRIPTION", "描述")
|
||||
cli.CommandHelpTemplate = strings.ReplaceAll(cli.CommandHelpTemplate, "OPTIONS", "选项")
|
||||
cli.SubcommandHelpTemplate = strings.ReplaceAll(cli.SubcommandHelpTemplate, "NAME", "名称")
|
||||
cli.SubcommandHelpTemplate = strings.ReplaceAll(cli.SubcommandHelpTemplate, "USAGE", "用法")
|
||||
cli.SubcommandHelpTemplate = strings.ReplaceAll(cli.SubcommandHelpTemplate, "DESCRIPTION", "描述")
|
||||
cli.SubcommandHelpTemplate = strings.ReplaceAll(cli.SubcommandHelpTemplate, "COMMANDS", "命令")
|
||||
cli.SubcommandHelpTemplate = strings.ReplaceAll(cli.SubcommandHelpTemplate, "OPTIONS", "选项")
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
cli.RootCommandHelpTemplate += "\n官网:https://panel.haozi.net"
|
||||
cli.RootCommandHelpTemplate += "\n论坛:https://tom.moe"
|
||||
cli.RootCommandHelpTemplate += "\nQ群:12370907\n"
|
||||
|
||||
cmd := &cli.Command{
|
||||
Name: "panel-cli",
|
||||
Usage: "耗子面板命令行工具",
|
||||
Version: panel.Version,
|
||||
Commands: route.Cli(),
|
||||
}
|
||||
if err := cmd.Run(context.Background(), os.Args); err != nil {
|
||||
panic(fmt.Sprintf("failed to run cli: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,281 @@
|
||||
package route
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli/v2"
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/TheTNB/panel/internal/service"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
func Cli() []*cli.Command {
|
||||
cliService := service.NewCliService()
|
||||
//cliService := service.NewCliService()
|
||||
return []*cli.Command{
|
||||
{
|
||||
Name: "test",
|
||||
Aliases: []string{"t"},
|
||||
Usage: "print a test message",
|
||||
Action: cliService.Test,
|
||||
Name: "restart",
|
||||
Usage: "重启面板服务",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "stop",
|
||||
Usage: "停止面板服务",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "start",
|
||||
Usage: "启动面板服务",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "update",
|
||||
Usage: "升级面板主程序",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "update-cli",
|
||||
Usage: "升级面板命令行工具",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "info",
|
||||
Usage: "输出面板基本信息",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "user",
|
||||
Usage: "操作面板用户",
|
||||
Commands: []*cli.Command{
|
||||
{
|
||||
Name: "list",
|
||||
Usage: "列出所有用户",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "username",
|
||||
Usage: "修改用户名",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "password",
|
||||
Usage: "修改用户密码",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "https",
|
||||
Usage: "操作面板HTTPS",
|
||||
Commands: []*cli.Command{
|
||||
{
|
||||
Name: "on",
|
||||
Usage: "开启HTTPS",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "off",
|
||||
Usage: "关闭HTTPS",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "entrance",
|
||||
Usage: "操作面板访问入口",
|
||||
Commands: []*cli.Command{
|
||||
{
|
||||
Name: "on",
|
||||
Usage: "开启访问入口",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "off",
|
||||
Usage: "关闭访问入口",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "port",
|
||||
Usage: "修改面板端口",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "website",
|
||||
Usage: "网站管理",
|
||||
Commands: []*cli.Command{
|
||||
{
|
||||
Name: "add",
|
||||
Usage: "创建新站点",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("new task template: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "remove",
|
||||
Usage: "移除站点",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("removed task template: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "delete",
|
||||
Usage: "删除站点(包括站点目录、同名数据库)",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("removed task template: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "write",
|
||||
Usage: "写入网站数据(仅限指导下使用)",
|
||||
Hidden: true,
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("removed task template: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "backup",
|
||||
Usage: "备份数据",
|
||||
Commands: []*cli.Command{
|
||||
{
|
||||
Name: "website",
|
||||
Usage: "备份网站",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("new task template: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "database",
|
||||
Usage: "备份数据库",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("removed task template: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "panel",
|
||||
Usage: "备份面板",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("removed task template: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "cutoff",
|
||||
Usage: "日志切割",
|
||||
Commands: []*cli.Command{
|
||||
{
|
||||
Name: "website",
|
||||
Usage: "网站",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("new task template: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "writeApp",
|
||||
Usage: "添加面板应用标记(仅限指导下使用)",
|
||||
Hidden: true,
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "removeApp",
|
||||
Usage: "移除面板应用标记(仅限指导下使用)",
|
||||
Hidden: true,
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "cleanTask",
|
||||
Usage: "清理面板任务队列(仅限指导下使用)",
|
||||
Hidden: true,
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "writeSetting",
|
||||
Usage: "写入面板设置(仅限指导下使用)",
|
||||
Hidden: true,
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "removeSetting",
|
||||
Usage: "移除面板设置(仅限指导下使用)",
|
||||
Hidden: true,
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("completed task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "init",
|
||||
Usage: "初始化面板(仅限指导下使用)",
|
||||
Hidden: true,
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println("added task: ", cmd.Args().First())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user