main.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. UpgradeDockerStep2Command,
  30. },
  31. Flags: []cli.Flag{
  32. &cli.StringFlag{
  33. Name: "config",
  34. Value: "app.ini",
  35. Usage: "configuration file path",
  36. },
  37. },
  38. DefaultCommand: "serve",
  39. Version: version.Version,
  40. }
  41. // Set the version printer
  42. cli.VersionPrinter = VersionPrinter
  43. if err := cmd.Run(context.Background(), os.Args); err != nil {
  44. log.Fatal(err)
  45. } else if !serve {
  46. os.Exit(0)
  47. }
  48. return cmd
  49. }