Browse Source

feat(cmd)!: remove token flag (#704)

Ayyan 3 tháng trước cách đây
mục cha
commit
607b5486de
4 tập tin đã thay đổi với 27 bổ sung24 xóa
  1. 5 7
      README.md
  2. 1 16
      cmd/root.go
  3. 12 1
      internal/app/app.go
  4. 9 0
      logs.txt

+ 5 - 7
README.md

@@ -48,23 +48,21 @@ go build .
 
 ## Usage
 
-### Token (UI)
+### Token (UI, recommended)
 
 1. Run the `discordo` executable with no arguments.
 
 2. Enter your token and click on the "Login" button to save it.
 
-### Token (CLI)
+### Token (environment variable)
 
-Provide the `token` command-line flag to the executable. 
+Set the value of the `DISCORDO_TOKEN` environment variable to the authentication token to log in with.
 
 ```sh
-discordo --token "OTI2MDU5NTQxNDE2Nzc5ODA2.Yc2KKA.2iZ-5JxgxG-9Ub8GHzBSn-NJjNg"
+DISCORDO_TOKEN="OTI2MDU5NTQxNDE2Nzc5ODA2.Yc2KKA.2iZ-5JxgxG-9Ub8GHzBSn-NJjNg" discordo
 ```
 
-Alternatively, set the value of the `DISCORDO_TOKEN` environment variable to the authentication token.
-
-### QR
+### QR (UI)
 
 1. Run the `discordo` executable with no arguments.
 

+ 1 - 16
cmd/root.go

@@ -4,24 +4,20 @@ import (
 	"flag"
 	"fmt"
 	"log/slog"
-	"os"
 
 	"github.com/ayn2op/discordo/internal/app"
 	"github.com/ayn2op/discordo/internal/config"
-	"github.com/ayn2op/discordo/internal/keyring"
 	"github.com/ayn2op/discordo/internal/logger"
 	"github.com/diamondburned/arikawa/v3/utils/ws"
 )
 
 var (
-	token      string
 	configPath string
 	logPath    string
 	logLevel   string
 )
 
 func Run() error {
-	flag.StringVar(&token, "token", "", "authentication token (default: $DISCORDO_TOKEN or keyring)")
 	flag.StringVar(&configPath, "config-path", config.DefaultPath(), "path of the configuration file")
 	flag.StringVar(&logPath, "log-path", logger.DefaultPath(), "path of the log file")
 	flag.StringVar(&logLevel, "log-level", "info", "log level")
@@ -49,16 +45,5 @@ func Run() error {
 		return fmt.Errorf("failed to load config: %w", err)
 	}
 
-	if token == "" {
-		token = os.Getenv("DISCORDO_TOKEN")
-	}
-
-	if token == "" {
-		token, err = keyring.GetToken()
-		if err != nil {
-			slog.Info("failed to retrieve token from keyring", "err", err)
-		}
-	}
-
-	return app.New(cfg).Run(token)
+	return app.New(cfg).Run()
 }

+ 12 - 1
internal/app/app.go

@@ -3,10 +3,12 @@ package app
 import (
 	"fmt"
 	"log/slog"
+	"os"
 
 	"github.com/ayn2op/discordo/internal/clipboard"
 	"github.com/ayn2op/discordo/internal/config"
 	"github.com/ayn2op/discordo/internal/consts"
+	"github.com/ayn2op/discordo/internal/keyring"
 	"github.com/ayn2op/discordo/internal/ui/chat"
 	"github.com/ayn2op/discordo/internal/ui/login"
 	"github.com/ayn2op/tview"
@@ -34,7 +36,16 @@ func New(cfg *config.Config) *App {
 	return app
 }
 
-func (a *App) Run(token string) error {
+func (a *App) Run() error {
+	token := os.Getenv("DISCORDO_TOKEN")
+	if token == "" {
+		t, err := keyring.GetToken()
+		if err != nil {
+			slog.Info("failed to retrieve token from keyring", "err", err)
+		}
+		token = t
+	}
+
 	screen, err := tcell.NewScreen()
 	if err != nil {
 		return fmt.Errorf("failed to create screen: %w", err)

+ 9 - 0
logs.txt

@@ -0,0 +1,9 @@
+time=2026-01-14T10:35:17.794-05:00 level=INFO msg="failed to retrieve token from keyring" err="secret not found in keyring"
+time=2026-01-14T10:35:47.288-05:00 level=DEBUG msg="new raw event" code=10 type=""
+time=2026-01-14T10:35:49.430-05:00 level=DEBUG msg="new raw event" code=0 type=READY
+time=2026-01-14T10:35:49.577-05:00 level=DEBUG msg="new raw event" code=0 type=MESSAGE_CREATE
+time=2026-01-14T10:35:49.577-05:00 level=DEBUG msg="new raw event" code=0 type=SESSIONS_REPLACE
+time=2026-01-14T10:35:52.995-05:00 level=DEBUG msg="new raw event" code=0 type=MESSAGE_UPDATE
+time=2026-01-14T10:35:56.516-05:00 level=DEBUG msg="new raw event" code=0 type=THREAD_LIST_SYNC
+time=2026-01-14T10:35:57.931-05:00 level=DEBUG msg="new HTTP request" method=GET url=https://discord.com/api/v9/channels/1297292231299956791/messages
+time=2026-01-14T10:35:58.479-05:00 level=DEBUG msg="new raw event" code=0 type=GUILD_MEMBERS_CHUNK