diff --git a/README.md b/README.md index d9d160e..a8ab053 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ sudo mv ./discordo /usr/local/bin - Log in using the account email and password (first-time login) and click on the "Login" button to continue. - - If you are using a bot account to login, set the `token` command-line flag to the token of the bot and prefix it with `Bot ` (eg: `--token "Bot OTI2MDU5NTQxNDE2Nzc5ODA2.Yc2KKA.2iZ-5JxgxG-9Ub8GHzBSn-NJjNg"`). + - If you are using a bot account to login, set the `token` command-line flag to the token of the bot and prefix it with `Bot ` (eg: `-token "Bot OTI2MDU5NTQxNDE2Nzc5ODA2.Yc2KKA.2iZ-5JxgxG-9Ub8GHzBSn-NJjNg"`). - By default, Discordo utilizes OS-specific keyring to store the authentication token. However, if you prefer not to use a keyring (not recommended), you may set the `token` command-line flag to the authentication token and Discordo will prioritize the usage of the provided token to login instead of keyring. diff --git a/config/pkg.go b/config/pkg.go index 798fb9a..125dc52 100644 --- a/config/pkg.go +++ b/config/pkg.go @@ -8,16 +8,15 @@ import ( ) type Config struct { - Token string `toml:"-" name:"token" help:"The authentication token." short:"T"` - Config string `toml:"-" name:"config" help:"The path of the configuration file." default:"${config}" type:"path" short:"C"` - - General GeneralConfig `toml:"general" kong:"-"` - Theme ThemeConfig `toml:"theme" kong:"-"` - Keys KeysConfig `toml:"keys" kong:"-"` + Path string `toml:"-"` + General GeneralConfig `toml:"general"` + Theme ThemeConfig `toml:"theme"` + Keys KeysConfig `toml:"keys"` } func New() *Config { return &Config{ + Path: DefaultPath(), General: newGeneralConfig(), Theme: newThemeConfig(), Keys: newKeysConfig(), @@ -25,13 +24,13 @@ func New() *Config { } func (c *Config) Load() { - err := os.MkdirAll(filepath.Dir(c.Config), os.ModePerm) + err := os.MkdirAll(filepath.Dir(c.Path), os.ModePerm) if err != nil { panic(err) } - if _, err = os.Stat(c.Config); os.IsNotExist(err) { - f, err := os.Create(c.Config) + if _, err = os.Stat(c.Path); os.IsNotExist(err) { + f, err := os.Create(c.Path) if err != nil { panic(err) } @@ -41,7 +40,7 @@ func (c *Config) Load() { panic(err) } } else { - _, err = toml.DecodeFile(c.Config, &c) + _, err = toml.DecodeFile(c.Path, &c) if err != nil { panic(err) } diff --git a/go.mod b/go.mod index 3722e97..7eca53b 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.18 require ( github.com/BurntSushi/toml v1.0.0 - github.com/alecthomas/kong v0.5.0 github.com/atotto/clipboard v0.1.4 github.com/ayntgl/discordgo v0.23.3-0.20220124081725-decdb6a611b6 github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1 @@ -16,15 +15,16 @@ require ( require ( github.com/alessio/shellescape v1.4.1 // indirect github.com/danieljoos/wincred v1.1.2 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/gdamore/encoding v1.0.0 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect - github.com/pkg/errors v0.9.1 // indirect github.com/rivo/uniseg v0.2.0 // indirect golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect - golang.org/x/sys v0.0.0-20220315194320-039c03cc5b86 // indirect + golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf // indirect golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/text v0.3.7 // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/go.sum b/go.sum index 3a9d606..19a10bb 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,5 @@ github.com/BurntSushi/toml v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU= github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= -github.com/alecthomas/kong v0.5.0 h1:u8Kdw+eeml93qtMZ04iei0CFYve/WPcA5IFh+9wSskE= -github.com/alecthomas/kong v0.5.0/go.mod h1:uzxf/HUh0tj43x1AyJROl3JT7SgsZ5m+icOv1csRhc0= -github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142 h1:8Uy0oSf5co/NZXje7U1z8Mpep++QJOldL2hs/sBQf48= -github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8= github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0= github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= @@ -30,8 +26,6 @@ github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69 github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/tview v0.0.0-20220307222120-9994674d60a8 h1:xe+mmCnDN82KhC010l3NfYlA8ZbOuzbXAzSYBa6wbMc= @@ -56,6 +50,8 @@ golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210819135213-f52c844e1c1c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220315194320-039c03cc5b86 h1:A9i04dxx7Cribqbs8jf3FQLogkL/CV2YN7hj9KWJCkc= golang.org/x/sys v0.0.0-20220315194320-039c03cc5b86/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf h1:Fm4IcnUL803i92qDlmB0obyHmosDrxZWxJL3gIeNqOw= +golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/main.go b/main.go index 3955166..78a8d6e 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,8 @@ package main import ( - "github.com/alecthomas/kong" + "flag" + "github.com/ayntgl/discordo/config" "github.com/ayntgl/discordo/discord" "github.com/ayntgl/discordo/ui" @@ -13,22 +14,25 @@ import ( const name = "discordo" func main() { - cfg := config.New() - kong.Parse(cfg, - kong.Name(name), - kong.UsageOnError(), - kong.Vars{ - "config": config.DefaultPath(), - }, - ) + var token string + var cfg string + flag.StringVar(&token, "token", "", "The authentication token.") + flag.StringVar(&cfg, "config", "", "The path of the configuration file.") + flag.Parse() - if cfg.Token == "" { - cfg.Token, _ = keyring.Get(name, "token") + if token == "" { + token, _ = keyring.Get(name, "token") } - app := ui.NewApp(cfg) - if cfg.Token != "" { - err := app.Connect(cfg.Token) + c := config.New() + if cfg != "" { + c.Path = cfg + } + c.Load() + + app := ui.NewApp(c) + if token != "" { + err := app.Connect(token) if err != nil { panic(err) } diff --git a/ui/app.go b/ui/app.go index 8598c24..fd1b291 100644 --- a/ui/app.go +++ b/ui/app.go @@ -30,8 +30,6 @@ func NewApp(c *config.Config) *App { SelectedMessage: -1, } - c.Load() - app.GuildsList = NewGuildsList(app) app.ChannelsTreeView = NewChannelsTreeView(app) app.MessagesTextView = NewMessagesTextView(app)