main.go 1.0 KB

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