magic/cmd/nginx/command.go
2026-03-28 19:25:12 +08:00

50 lines
836 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package nginx
import (
"fmt"
"github.com/urfave/cli/v2"
"gitea.micah.wiki/pandora/magic/config"
)
func Nginx() *cli.Command {
return &cli.Command{
Name: "nginx",
Action: func(c *cli.Context) error {
conf := config.Get()
if len(conf.Nginx) == 0 {
return fmt.Errorf("未找到nginx的配置")
}
current, err := ReadCurrent(c.Context, conf)
if err != nil {
return err
}
exist, err := Check(c.Context, current)
if err != nil {
return err
}
if !exist {
return fmt.Errorf("在 $PATH 中未找到nginx请自行安装并配置在 $PATH 中")
}
err = Create(c.Context, current)
if err != nil {
return err
}
restart := ReadRestart(c.Context)
if restart {
err = ReStart(c.Context)
if err != nil {
return err
}
}
return nil
},
}
}