From 607b5486de56863acab4b09693b35d71b8ee5252 Mon Sep 17 00:00:00 2001 From: Ayyan Date: Wed, 14 Jan 2026 10:42:19 -0500 Subject: [PATCH] feat(cmd)!: remove token flag (#704) --- README.md | 12 +++++------- cmd/root.go | 17 +---------------- internal/app/app.go | 13 ++++++++++++- logs.txt | 9 +++++++++ 4 files changed, 27 insertions(+), 24 deletions(-) create mode 100755 logs.txt diff --git a/README.md b/README.md index 6fd52ea..bbe9a3b 100644 --- a/README.md +++ b/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. diff --git a/cmd/root.go b/cmd/root.go index 232b091..242253b 100644 --- a/cmd/root.go +++ b/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() } diff --git a/internal/app/app.go b/internal/app/app.go index a8fa5c3..4af58ef 100644 --- a/internal/app/app.go +++ b/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) diff --git a/logs.txt b/logs.txt new file mode 100755 index 0000000..f08aad2 --- /dev/null +++ b/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