main.go 919 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package cmd
  2. import (
  3. "context"
  4. "fmt"
  5. "log"
  6. "os"
  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. Flags: []cli.Flag{
  26. &cli.StringFlag{
  27. Name: "config",
  28. Value: "app.ini",
  29. Usage: "configuration file path",
  30. },
  31. },
  32. DefaultCommand: "serve",
  33. Version: version.Version,
  34. }
  35. cli.VersionPrinter = func(cmd *cli.Command) {
  36. fmt.Printf("%s (%d)\n", cmd.Root().Version, version.BuildId)
  37. }
  38. if err := cmd.Run(context.Background(), os.Args); err != nil {
  39. log.Fatal(err)
  40. } else if !serve {
  41. os.Exit(0)
  42. }
  43. return cmd
  44. }