main.go 715 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package cmd
  2. import (
  3. "context"
  4. "log"
  5. "os"
  6. "github.com/urfave/cli/v3"
  7. )
  8. func NewAppCmd() *cli.Command {
  9. serve := false
  10. cmd := &cli.Command{
  11. Name: "nginx-ui",
  12. Usage: "Yet another Nginx Web UI",
  13. Commands: []*cli.Command{
  14. {
  15. Name: "serve",
  16. Usage: "Start the Nginx-UI server",
  17. Action: func(ctx context.Context, command *cli.Command) error {
  18. serve = true
  19. return nil
  20. },
  21. },
  22. },
  23. Flags: []cli.Flag{
  24. &cli.StringFlag{
  25. Name: "config",
  26. Value: "app.ini",
  27. Usage: "configuration file path",
  28. },
  29. },
  30. DefaultCommand: "serve",
  31. }
  32. if err := cmd.Run(context.Background(), os.Args); err != nil {
  33. log.Fatal(err)
  34. } else if !serve {
  35. os.Exit(0)
  36. }
  37. return cmd
  38. }