There's now a --account parameter to define which account to access on startup
MODIFY
app/app.go
app/app.go
@@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
+ "strings"
"github.com/Bios-Marcel/cordless/tview"
"github.com/Bios-Marcel/discordgo"
@@ -16,9 +17,11 @@ import (
"github.com/Bios-Marcel/cordless/version"
)
-// Run launches the whole application and might abort in case it encounters an
-//error.
-func Run() {
+// RunWithAccount launches the whole application and might
+// abort in case it encounters an error. The login will attempt
+// using the account specified, unless the argument is empty.
+// If the account can't be found, the login page will be shown.
+func RunWithAccount(account string) {
configDir, configErr := config.GetConfigDirectory()
if configErr != nil {
@@ -36,6 +39,9 @@ func Run() {
runNext := make(chan bool, 1)
configuration, configLoadError := config.LoadConfig()
+ if strings.TrimSpace(account) != "" {
+ configuration.Token = configuration.GetAccountToken(account)
+ }
if configLoadError != nil {
log.Fatalf("Error loading configuration file (%s).\n", configLoadError.Error())
@@ -164,6 +170,12 @@ func Run() {
}
}
+// Run launches the whole application and might abort in case
+// it encounters an error.
+func Run() {
+ RunWithAccount("")
+}
+
func attemptLogin(loginScreen *ui.Login, loginMessage string, configuration *config.Config) (*discordgo.Session, *discordgo.Ready) {
var (
session *discordgo.Session

MODIFY
config/config.go
config/config.go
@@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
+ "strings"
"github.com/Bios-Marcel/cordless/util/files"
)
@@ -162,6 +163,18 @@ type Account struct {
Token string
}
+// GetAccountToken returns the token for the given account or an empty string
+// if the account can't be found or has no token set up.
+func (config *Config) GetAccountToken(account string) string {
+ for _, acc := range config.Accounts {
+ if strings.EqualFold(acc.Name, account) {
+ return acc.Token
+ }
+ }
+
+ return ""
+}
+
var cachedConfigDir string
var cachedConfigFile string
var cachedScriptDir string

MODIFY
main.go
main.go
@@ -18,6 +18,7 @@ func main() {
setConfigDirectory := flag.String("config-dir", "", "Sets the configuration directory")
setScriptDirectory := flag.String("script-dir", "", "Sets the script directory")
setConfigFilePath := flag.String("config-file", "", "Sets exact path of the configuration file")
+ accountToUse := flag.String("account", "", "Defines which account cordless tries to load")
flag.Parse()
if setConfigDirectory != nil {
@@ -34,7 +35,11 @@ func main() {
shortcutdialog.RunShortcutsDialogStandalone()
} else if showVersion != nil && *showVersion {
fmt.Printf("You are running cordless version %s\nKeep in mind that this version might not be correct for manually built versions, as those can contain additional commits.\n", version.Version)
+ } else {
+ if accountToUse != nil && *accountToUse != "" {
+ app.RunWithAccount(*accountToUse)
} else {
app.Run()
}
}
+}

There's now a --account parameter to define which account to access on startup