main.go 864 B

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