🏗️ move make sub-cmd to sub-dir

This commit is contained in:
zhaoyupeng
2025-11-25 15:46:28 +08:00
parent 454e0639a0
commit 62b680dca8
27 changed files with 750 additions and 105 deletions

View File

@@ -5,6 +5,7 @@ import (
"gitea.loveuer.com/yizhisec/pkg3/logger"
"github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/cmd/makecmd"
"yizhisec.com/hsv2/forge/internal/controller/maker"
"yizhisec.com/hsv2/forge/internal/opt"
)
@@ -25,6 +26,10 @@ func makeCmd() *cobra.Command {
logger.Warn("Running in debug mode")
}
if err = os.MkdirAll(opt.Cfg.Make.Dir, 0755); err != nil {
return err
}
if opt.Cfg.Make.DisableDependencyCheck {
logger.Info("Dependency check disabled")
return nil
@@ -35,10 +40,6 @@ func makeCmd() *cobra.Command {
return err
}
if err = os.MkdirAll(opt.Cfg.Make.Dir, 0755); err != nil {
return err
}
logger.Debug("Running make prerun success")
return nil
@@ -49,18 +50,20 @@ func makeCmd() *cobra.Command {
_cmd.PersistentFlags().StringVar(&opt.Cfg.Make.Dir, "dir", "/root/hsv2-installation", "make base directory")
_cmd.AddCommand(
makeImages(),
makeBinaries(),
makeDebs(),
makeFlannel(),
makeLonghorn(),
makeMysql(),
makeRedis(),
makeES(),
makeEMQX(),
makeYosguard(),
makeLessDNS(), // hs-net dependency
makeHSNet(),
makecmd.Images(),
makecmd.Binaries(),
makecmd.Debs(),
makecmd.Flannel(),
makecmd.Longhorn(),
makecmd.Mysql(),
makecmd.Redis(),
makecmd.ES(),
makecmd.EMQX(),
makecmd.Yosguard(),
makecmd.LessDNS(),
makecmd.HSNet(),
makecmd.ConfigMap(),
makecmd.App(),
)
return _cmd

View File

@@ -0,0 +1,18 @@
package makecmd
import (
"github.com/spf13/cobra"
)
func App() *cobra.Command {
_cmd := &cobra.Command{
Use: "app",
Short: "Make Apps(user, client, gateway, mie, nginx, etc...)",
}
_cmd.AddCommand(
appUser(),
)
return _cmd
}

View File

@@ -0,0 +1,25 @@
package makecmd
import (
"github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker"
)
func appUser() *cobra.Command {
var (
replica int
)
_cmd := &cobra.Command{
Use: "user",
Short: "Make User App",
RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker()
return mk.AppUser(cmd.Context(), replica)
},
}
_cmd.Flags().IntVar(&replica, "replica-count", 2, "Replica count")
return _cmd
}

View File

@@ -1,11 +1,11 @@
package cmd
package makecmd
import (
"github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker"
)
func makeBinaries() *cobra.Command {
func Binaries() *cobra.Command {
cmd := &cobra.Command{
Use: "binaries",
Aliases: []string{"bin", "B"},

View File

@@ -0,0 +1,20 @@
package makecmd
import (
"github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker"
)
func ConfigMap() *cobra.Command {
_cmd := &cobra.Command{
Use: "configmap",
Aliases: []string{"cm"},
Short: "构建 ConfigMap",
RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker()
return mk.ConfigMap(cmd.Context())
},
}
return _cmd
}

View File

@@ -1,11 +1,11 @@
package cmd
package makecmd
import (
"github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker"
)
func makeDebs() *cobra.Command {
func Debs() *cobra.Command {
cmd := &cobra.Command{
Use: "debs",
Aliases: []string{"deb"},

View File

@@ -1,11 +1,11 @@
package cmd
package makecmd
import (
"github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker"
)
func makeEMQX() *cobra.Command {
func EMQX() *cobra.Command {
_cmd := &cobra.Command{
Use: "emqx",
Short: "Make EMQX",

View File

@@ -1,4 +1,4 @@
package cmd
package makecmd
import (
"fmt"
@@ -7,7 +7,7 @@ import (
"yizhisec.com/hsv2/forge/internal/controller/maker"
)
func makeES() *cobra.Command {
func ES() *cobra.Command {
var (
makeHelper bool
memRate int

View File

@@ -1,11 +1,11 @@
package cmd
package makecmd
import (
"github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker"
)
func makeFlannel() *cobra.Command {
func Flannel() *cobra.Command {
var (
_mode string
)

View File

@@ -1,11 +1,11 @@
package cmd
package makecmd
import (
"github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker"
)
func makeHSNet() *cobra.Command {
func HSNet() *cobra.Command {
_cmd := &cobra.Command{
Use: "hs-net",
Short: "Build hs-net",

View File

@@ -1,4 +1,4 @@
package cmd
package makecmd
import (
"os"
@@ -9,7 +9,7 @@ import (
"yizhisec.com/hsv2/forge/internal/opt"
)
func makeImages() *cobra.Command {
func Images() *cobra.Command {
cmd := &cobra.Command{
Use: "images",
Aliases: []string{"image"},

View File

@@ -1,11 +1,11 @@
package cmd
package makecmd
import (
"github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker"
)
func makeLessDNS() *cobra.Command {
func LessDNS() *cobra.Command {
_cmd := &cobra.Command{
Use: "lessdns",
Short: "Build lessdns",

View File

@@ -1,11 +1,11 @@
package cmd
package makecmd
import (
"github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker"
)
func makeLonghorn() *cobra.Command {
func Longhorn() *cobra.Command {
var (
replicaCount int
)

View File

@@ -1,4 +1,4 @@
package cmd
package makecmd
import (
"fmt"
@@ -7,8 +7,7 @@ import (
"yizhisec.com/hsv2/forge/internal/controller/maker"
)
func makeMysql() *cobra.Command {
func Mysql() *cobra.Command {
var (
replicas int
storage int

View File

@@ -1,11 +1,11 @@
package cmd
package makecmd
import (
"github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker"
)
func makeRedis() *cobra.Command {
func Redis() *cobra.Command {
var (
replicas int
password string

View File

@@ -1,11 +1,11 @@
package cmd
package makecmd
import (
"github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker"
)
func makeYosguard() *cobra.Command {
func Yosguard() *cobra.Command {
_cmd := &cobra.Command{
Use: "yosguard",
Aliases: []string{"YOS"},