app.go 798 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package pcmserver
  2. import (
  3. "dy-admin/internal/pcmserver/config"
  4. "dy-admin/internal/pcmserver/options"
  5. "dy-admin/pkg/app"
  6. "dy-admin/pkg/log"
  7. )
  8. const commandDesc = `pcm(phone cabinet manager) system command description`
  9. // NewApp creates an App object with default parameters.
  10. func NewApp(basename string) *app.App {
  11. opts := options.NewOptions()
  12. application := app.NewApp("pcm server",
  13. basename,
  14. app.WithOptions(opts),
  15. app.WithDescription(commandDesc),
  16. app.WithDefaultValidArgs(),
  17. app.WithRunFunc(run(opts)),
  18. )
  19. return application
  20. }
  21. func run(opts *options.Options) app.RunFunc {
  22. return func(basename string) error {
  23. log.Init(opts.LogOptions)
  24. defer log.Flush()
  25. cfg, err := config.CreateConfigFromOptions(opts)
  26. if err != nil {
  27. return err
  28. }
  29. return Run(cfg)
  30. }
  31. }