refactor(run): use std::flag instead

This commit is contained in:
ayn2op 2023-10-20 15:07:18 +05:30
parent fcdab3d990
commit a8b3c19067
3 changed files with 11 additions and 50 deletions

View file

@ -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()
}

View file

@ -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`

14
main.go
View file

@ -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)
}
}