root.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package cmd
  2. import (
  3. "log/slog"
  4. "github.com/ayn2op/discordo/internal/config"
  5. "github.com/ayn2op/discordo/internal/consts"
  6. "github.com/ayn2op/discordo/internal/logger"
  7. "github.com/rivo/tview"
  8. "github.com/spf13/cobra"
  9. "github.com/zalando/go-keyring"
  10. )
  11. var (
  12. discordState *State
  13. app *App
  14. )
  15. var (
  16. rootCmd = &cobra.Command{
  17. RunE: func(cmd *cobra.Command, args []string) error {
  18. if err := logger.Load(); err != nil {
  19. return err
  20. }
  21. token, _ := cmd.Flags().GetString("token")
  22. if token == "" {
  23. var err error
  24. token, err = keyring.Get(consts.Name, "token")
  25. if err != nil {
  26. slog.Info("failed to retrieve token from keyring", "err", err)
  27. }
  28. }
  29. cfg, err := config.Load()
  30. if err != nil {
  31. return err
  32. }
  33. tview.Borders.Horizontal = cfg.Theme.Border.Preset.Horizontal
  34. tview.Borders.Vertical = cfg.Theme.Border.Preset.Vertical
  35. tview.Borders.TopLeft = cfg.Theme.Border.Preset.TopLeft
  36. tview.Borders.TopRight = cfg.Theme.Border.Preset.TopRight
  37. tview.Borders.BottomLeft = cfg.Theme.Border.Preset.BottomLeft
  38. tview.Borders.BottomRight = cfg.Theme.Border.Preset.BottomRight
  39. tview.Borders.HorizontalFocus = tview.Borders.Horizontal
  40. tview.Borders.VerticalFocus = tview.Borders.Vertical
  41. tview.Borders.TopLeftFocus = tview.Borders.TopLeft
  42. tview.Borders.TopRightFocus = tview.Borders.TopRight
  43. tview.Borders.BottomLeftFocus = tview.Borders.BottomLeft
  44. tview.Borders.BottomRightFocus = tview.Borders.BottomRight
  45. app = newApp(cfg)
  46. return app.run(token)
  47. },
  48. }
  49. Execute = rootCmd.Execute
  50. )
  51. func init() {
  52. rootCmd.Flags().StringP("token", "t", "", "the authentication token")
  53. }