From a8b3c19067005c7d6987971b24a39df7a2d1060c Mon Sep 17 00:00:00 2001 From: ayn2op Date: Fri, 20 Oct 2023 15:07:18 +0530 Subject: [PATCH] refactor(run): use std::flag instead --- cmd/run/run.go | 10 +++------- docs/configuration.md | 37 ++++--------------------------------- main.go | 14 ++++---------- 3 files changed, 11 insertions(+), 50 deletions(-) diff --git a/cmd/run/run.go b/cmd/run/run.go index 5bee3cb..d4c04db 100644 --- a/cmd/run/run.go +++ b/cmd/run/run.go @@ -17,11 +17,7 @@ var ( mainFlex *MainFlex ) -type Cmd struct { - Token string `default:"${token}" help:"The authentication token." short:"t"` -} - -func (r *Cmd) Run() error { +func Run(token string) error { path := config.DefaultPath() err := os.MkdirAll(filepath.Dir(path), os.ModePerm) if err != nil { @@ -47,7 +43,7 @@ func (r *Cmd) Run() error { log.SetOutput(f) log.SetFlags(log.LstdFlags | log.Llongfile) - if r.Token == "" { + if token == "" { lf := ui.NewLoginForm() go func() { @@ -70,7 +66,7 @@ func (r *Cmd) Run() error { app.SetRoot(lf, true) } else { mainFlex = newMainFlex() - if err := openState(r.Token); err != nil { + if err := openState(token); err != nil { app.Stop() } diff --git a/docs/configuration.md b/docs/configuration.md index bd09a55..23935e1 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1,36 +1,7 @@ # Configuration -The configuration file allows you to customize behavior, keybindings, and theme of the application. It is created on first start-up at the following location: +The configuration file allows you to configure and customize the behavior, keybindings, and theme of the application. It is automatically created on first start-up at the following location: -| Operating System | Configuration File Location | -| ---------------- | ------------------------------------------------------- | -| Unix | `$HOME/.config/discordo/config.yml` | -| Darwin | `$HOME/Library/Application Support/discordo/config.yml` | -| Windows | `%AppData%/discordo/config.yml` | - -## Keybindings - -Keybindings are configurable in the [configuration file](#configuration). - -| Action | Keybinding | -| --------------------- | ---------- | -| **Guilds Tree** | | -| Focus | Alt + g | -| Toggle | Alt + b | -| | | -| **Messages Text** | | -| Focus | Alt + m | -| Show image | i | -| Copy message content | c | -| Reply without mention | r | -| Reply with mention | R | -| Select reply | s | -| Select previous | Up arrow | -| Select next | Down arrow | -| Select first | Home | -| Select last | End | -| | | -| **Message Input** | | -| Focus | Alt + i | -| Send message | Enter | -| Launch editor | Ctrl + e | +- Unix: `$XDG_CONFIG_HOME/discordo/config.yml` or `$HOME/.config/discordo/config.yml` +- Darwin: `$HOME/Library/Application Support/discordo/config.yml` +- Windows: `%AppData%/discordo/config.yml` diff --git a/main.go b/main.go index b46e173..7996c4f 100644 --- a/main.go +++ b/main.go @@ -1,26 +1,20 @@ package main import ( + "flag" "log" - "github.com/alecthomas/kong" "github.com/ayn2op/discordo/cmd/run" "github.com/ayn2op/discordo/config" "github.com/zalando/go-keyring" ) -var cli struct { - Run run.Cmd `cmd:"" default:"withargs"` -} - func main() { t, _ := keyring.Get(config.Name, "token") - ctx := kong.Parse(&cli, kong.Vars{ - "token": t, - }) + token := flag.String("token", t, "The authentication token.") + flag.Parse() - err := ctx.Run() - if err != nil { + if err := run.Run(*token); err != nil { log.Fatal(err) } }