This commit is contained in:
ZhuoQinghui 2024-12-27 17:08:15 +08:00
parent d505213d2c
commit a742f096f0
7 changed files with 140 additions and 25 deletions

View File

@ -1 +0,0 @@
package src

View File

@ -1,6 +1,7 @@
package cmd
import (
"acme-mana/src/cmd/cmd_handle"
"acme-mana/src/common"
"acme-mana/src/conf"
"github.com/spf13/cobra"
@ -52,7 +53,7 @@ func initConfCmd() *cobra.Command {
Short: "查看配置列表",
Long: "查看系统配置列表",
Run: func(cmd *cobra.Command, args []string) {
confShow(cmd, args)
cmd_handle.ConfShow(cmd, args)
},
}
confCmd.AddCommand(confShow)
@ -76,7 +77,7 @@ func initServerCmd() *cobra.Command {
Short: "编辑服务配置",
Long: "编辑服务配置",
Run: func(cmd *cobra.Command, args []string) {
editServer(cmd, args)
cmd_handle.ServerEdit(cmd, args)
},
}
stateCmd := &cobra.Command{
@ -84,7 +85,7 @@ func initServerCmd() *cobra.Command {
Short: "查看服务状态",
Long: "查看服务状态",
Run: func(cmd *cobra.Command, args []string) {
serverState(cmd, args)
cmd_handle.ServerState(cmd, args)
},
}
startCmd := &cobra.Command{
@ -92,7 +93,7 @@ func initServerCmd() *cobra.Command {
Short: "启动服务",
Long: "启动服务",
Run: func(cmd *cobra.Command, args []string) {
startServer(cmd, args)
cmd_handle.ServerStart(cmd, args)
},
}
stopCmd := &cobra.Command{
@ -100,7 +101,7 @@ func initServerCmd() *cobra.Command {
Short: "停止服务",
Long: "停止服务",
Run: func(cmd *cobra.Command, args []string) {
stopServer(cmd, args)
cmd_handle.ServerStop(cmd, args)
},
}
@ -125,7 +126,7 @@ func initTaskCmd() *cobra.Command {
Short: "编辑定时任务配置",
Long: "编辑定时任务配置",
Run: func(cmd *cobra.Command, args []string) {
editTask(cmd, args)
cmd_handle.TaskEdit(cmd, args)
},
}
startTask := &cobra.Command{
@ -133,7 +134,7 @@ func initTaskCmd() *cobra.Command {
Short: "启动定时任务",
Long: "启动定时任务",
Run: func(cmd *cobra.Command, args []string) {
startTask(cmd, args)
cmd_handle.TaskStart(cmd, args)
},
}
stopTask := &cobra.Command{
@ -141,7 +142,7 @@ func initTaskCmd() *cobra.Command {
Short: "停止定时任务",
Long: "停止定时任务",
Run: func(cmd *cobra.Command, args []string) {
stopTask(cmd, args)
cmd_handle.TaskStop(cmd, args)
},
}
statusTask := &cobra.Command{
@ -149,7 +150,7 @@ func initTaskCmd() *cobra.Command {
Short: "查看定时任务状态",
Long: "查看定时任务状态",
Run: func(cmd *cobra.Command, args []string) {
statusTask(cmd, args)
cmd_handle.TaskStatus(cmd, args)
},
}
runTask := &cobra.Command{
@ -157,7 +158,7 @@ func initTaskCmd() *cobra.Command {
Short: "手动执行一次任务",
Long: "手动执行一次任务",
Run: func(cmd *cobra.Command, args []string) {
runTask(cmd, args)
cmd_handle.TaskRun(cmd, args)
},
}
taskCmd.AddCommand(editTask)
@ -182,7 +183,7 @@ func initProviderCmd() *cobra.Command {
Short: "列出支持的DNS服务商",
Long: "列出支持的DNS服务商",
Run: func(cmd *cobra.Command, args []string) {
providerSupport(cmd, args)
cmd_handle.ProviderSupport(cmd, args)
},
}
providerList := &cobra.Command{
@ -190,7 +191,7 @@ func initProviderCmd() *cobra.Command {
Short: "列出已配置的DNS服务商",
Long: "列出已配置的DNS服务商",
Run: func(cmd *cobra.Command, args []string) {
providerList(cmd, args)
cmd_handle.ProviderList(cmd, args)
},
}
providerAdd := &cobra.Command{
@ -198,7 +199,7 @@ func initProviderCmd() *cobra.Command {
Short: "添加DNS服务商",
Long: "添加DNS服务商",
Run: func(cmd *cobra.Command, args []string) {
providerAdd(cmd, args)
cmd_handle.ProviderAdd(cmd, args)
},
}
providerEdit := &cobra.Command{
@ -206,7 +207,7 @@ func initProviderCmd() *cobra.Command {
Short: "编辑DNS服务商",
Long: "编辑DNS服务商",
Run: func(cmd *cobra.Command, args []string) {
providerEdit(cmd, args)
cmd_handle.ProviderEdit(cmd, args)
},
}
providerDelete := &cobra.Command{
@ -214,7 +215,7 @@ func initProviderCmd() *cobra.Command {
Short: "删除DNS服务商",
Long: "删除DNS服务商",
Run: func(cmd *cobra.Command, args []string) {
providerDelete(cmd, args)
cmd_handle.ProviderDelete(cmd, args)
},
}
@ -240,7 +241,7 @@ func certCmd() *cobra.Command {
Short: "列出已配置的证书",
Long: "列出已配置的证书",
Run: func(cmd *cobra.Command, args []string) {
certList(cmd, args)
cmd_handle.CertList(cmd, args)
},
}
certAdd := &cobra.Command{
@ -248,7 +249,7 @@ func certCmd() *cobra.Command {
Short: "添加证书",
Long: "添加证书",
Run: func(cmd *cobra.Command, args []string) {
certAdd(cmd, args)
cmd_handle.CertAdd(cmd, args)
},
}
certDelete := &cobra.Command{
@ -256,7 +257,7 @@ func certCmd() *cobra.Command {
Short: "删除证书",
Long: "删除证书",
Run: func(cmd *cobra.Command, args []string) {
certDelete(cmd, args)
cmd_handle.CertDelete(cmd, args)
},
}
editCert := &cobra.Command{
@ -264,7 +265,7 @@ func certCmd() *cobra.Command {
Short: "编辑证书",
Long: "编辑证书",
Run: func(cmd *cobra.Command, args []string) {
editCert(cmd, args)
cmd_handle.CertEdit(cmd, args)
},
}
certCmd.AddCommand(certList)

View File

@ -0,0 +1,22 @@
package cmd_handle
import (
"fmt"
"github.com/spf13/cobra"
)
func CertEdit(cmd *cobra.Command, args []string) {
fmt.Println("edit cert")
}
func CertDelete(cmd *cobra.Command, args []string) {
fmt.Println("delete cert")
}
func CertAdd(cmd *cobra.Command, args []string) {
fmt.Println("add cert")
}
func CertList(cmd *cobra.Command, args []string) {
fmt.Println("list cert")
}

View File

@ -0,0 +1,19 @@
package cmd_handle
import (
"acme-mana/src/conf"
"encoding/json"
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/spf13/cobra"
)
// ConfShow 打印 配置信息
func ConfShow(cmd *cobra.Command, args []string) {
tea.Println()
confJson, err := json.MarshalIndent(conf.Config(), "", " ")
if err != nil {
fmt.Println("序列化配置信息失败:", err)
}
fmt.Println(string(confJson))
}

View File

@ -0,0 +1,26 @@
package cmd_handle
import (
"fmt"
"github.com/spf13/cobra"
)
func ProviderDelete(cmd *cobra.Command, args []string) {
fmt.Println("delete provider")
}
func ProviderEdit(cmd *cobra.Command, args []string) {
fmt.Println("edit provider")
}
func ProviderAdd(cmd *cobra.Command, args []string) {
fmt.Println("add provider")
}
func ProviderList(cmd *cobra.Command, args []string) {
fmt.Println("list provider")
}
func ProviderSupport(cmd *cobra.Command, args []string) {
fmt.Println("support provider")
}

View File

@ -2,7 +2,11 @@ package cmd_handle
import (
"acme-mana/src/common"
"acme-mana/src/conf"
"acme-mana/src/server"
"acme-mana/src/util"
"fmt"
"github.com/spf13/cobra"
"log"
"os"
"os/exec"
@ -15,20 +19,22 @@ import (
var stdout *os.File
var stderr *os.File
func start() {
func ServerStart(command *cobra.Command, args []string) {
initLog()
isDaemon := os.Getenv("GO_DAEMON")
log.Println("守护进程启动: " + isDaemon)
if isDaemon != "1" {
daemonStart()
return
}
if isRunning() {
log.Println("守护进程已启动, 跳过执行")
return
}
if isDaemon == "1" {
daemonStart()
return
}
workPath, err := os.Executable()
if err != nil {
log.Fatalf("无法获取当前工作路径: %v", err)
@ -56,6 +62,22 @@ func start() {
os.Exit(0)
}
func ServerEdit(cmd *cobra.Command, args []string) {
s := conf.Config().Server
host := util.ReadLine("请输入服务监听地址;", s.Host)
port := util.ReadInt("请输入服务监听端口;", strconv.Itoa(s.Port))
key := util.ReadLine("请输入服务通信认证秘钥;", s.Key)
conf.EditServer(host, port, key)
fmt.Println("服务监听配置已完成")
}
func ServerState(cmd *cobra.Command, args []string) {
server.HttpInstance.Status()
}
func ServerStop(cmd *cobra.Command, args []string) {
server.HttpInstance.Stop()
}
func daemonStart() {
// 启动 HttpServer
server.HttpInstance.Init()

View File

@ -0,0 +1,26 @@
package cmd_handle
import (
"fmt"
"github.com/spf13/cobra"
)
func TaskEdit(cmd *cobra.Command, args []string) {
fmt.Println("edit task")
}
func TaskStatus(cmd *cobra.Command, args []string) {
fmt.Println("status task")
}
func TaskStop(cmd *cobra.Command, args []string) {
fmt.Println("stop task")
}
func TaskStart(cmd *cobra.Command, args []string) {
fmt.Println("start task")
}
func TaskRun(cmd *cobra.Command, args []string) {
fmt.Println("run task")
}