mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-10-28 02:57:28 +08:00
style: 增加 1panel cli
This commit is contained in:
committed by
zhengkunwang223
parent
cec416b674
commit
275bbc17cc
@@ -0,0 +1,20 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
backupCmd.Flags().StringVarP(&configPath, "dir", "d", "/opt/backup", "备份目录")
|
||||
RootCmd.AddCommand(backupCmd)
|
||||
}
|
||||
|
||||
var backupCmd = &cobra.Command{
|
||||
Use: "backup",
|
||||
Short: "备份1Panel",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
fmt.Println("备份成功")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(restoreCmd)
|
||||
}
|
||||
|
||||
var restoreCmd = &cobra.Command{
|
||||
Use: "restore",
|
||||
Short: "回滚1Panel",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
fmt.Println("回滚成功")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/1Panel-dev/1Panel/backend/server"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
configPath string
|
||||
)
|
||||
|
||||
func init() {
|
||||
RootCmd.Flags().BoolP("run", "r", false, "运行面板")
|
||||
RootCmd.Flags().StringVarP(&configPath, "config", "c", "/opt/1panel/conf/app.yml", "配置文件路径")
|
||||
}
|
||||
|
||||
var RootCmd = &cobra.Command{
|
||||
Use: "1panel",
|
||||
Short: "1Panel ,一款现代化的 Linux 面板",
|
||||
Long: `欢迎使用 1Panel 面板
|
||||
github地址: https://github.com/1Panel-dev/1Panel
|
||||
你可以使用如下命令操作1Panel
|
||||
例如: 1panel -r 启动1Panel服务
|
||||
1panel backup -d /some/path 备份1Panel
|
||||
你也可以使用 1panel --help 查看帮助信息
|
||||
或者使用 1panel xx --help 查看具体命令的帮助信息`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 || args[0] == "run" || args[0] == "r" {
|
||||
server.Start()
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
+7
-2
@@ -1,8 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/1Panel-dev/1Panel/backend/server"
|
||||
"fmt"
|
||||
"github.com/1Panel-dev/1Panel/cmd/server/cmd"
|
||||
_ "github.com/1Panel-dev/1Panel/cmd/server/docs"
|
||||
"os"
|
||||
)
|
||||
|
||||
// @title 1Panel
|
||||
@@ -18,5 +20,8 @@ import (
|
||||
|
||||
//go:generate swag init -o ./docs -d ../../backend/app/api/v1 -g ../../../../cmd/server/main.go
|
||||
func main() {
|
||||
server.Start()
|
||||
if err := cmd.RootCmd.Execute(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user