feat(cmd)!: remove token flag (#704)
This commit is contained in:
parent
bcc1f4de28
commit
607b5486de
4 changed files with 27 additions and 24 deletions
12
README.md
12
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.
|
||||
|
||||
|
|
|
|||
17
cmd/root.go
17
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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
logs.txt
Executable file
9
logs.txt
Executable file
|
|
@ -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
|
||||
Loading…
Add table
Reference in a new issue