Skip to content

Commit 1a784df

Browse files
author
JojiiOfficial
committed
add setup from token
1 parent e5f0a6c commit 1a784df

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func runCommand(parsed string, commandData *commands.CommandData) {
157157
return
158158
}
159159

160-
commands.SetupClient(commandData, host, *appCfgFile, *setupCmdIgnoreCert, *setupCmdServerOnly, *setupCmdRegister, *setupCmdNoLogin)
160+
commands.SetupClient(commandData, host, *appCfgFile, *setupCmdIgnoreCert, *setupCmdServerOnly, *setupCmdRegister, *setupCmdNoLogin, *setupCmdToken, *setupCmdUsername)
161161
}
162162

163163
// -- Config commands

commands/Config.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ func ConfigView(cData *CommandData) {
111111
}
112112

113113
// SetupClient sets up client config
114-
func SetupClient(cData *CommandData, host, configFile string, ignoreCert, serverOnly, register, noLogin bool) {
114+
func SetupClient(cData *CommandData, host, configFile string, ignoreCert, serverOnly, register, noLogin bool, token, username string) {
115+
if len(token)*len(username) == 0 {
116+
fmt.Println("Either --user or --token is missing")
117+
return
118+
}
119+
115120
// Confirm creating a config anyway
116121
if cData.Config != nil && !cData.Config.IsDefault() && !cData.Yes {
117122
y, _ := gaw.ConfirmInput("There is already a config. Do you want to overwrite it? [y/n]> ", bufio.NewReader(os.Stdin))
@@ -161,6 +166,13 @@ func SetupClient(cData *CommandData, host, configFile string, ignoreCert, server
161166
config, _ := cData.Config.ToRequestConfig()
162167
cData.LibDM = libdm.NewLibDM(config)
163168

169+
// Insert user directly if token and user is set
170+
if len(token) > 0 && len(username) > 0 {
171+
cData.Config.InsertUser(username, token)
172+
cData.Config.Save()
173+
return
174+
}
175+
164176
// In register mode, don't login
165177
if register {
166178
noLogin = true

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ var (
9494
setupCmdServerOnly = setupCmd.Flag("server-only", "Setup the server connection only. No login").Bool()
9595
setupCmdRegister = setupCmd.Flag("register", "Register after logging in").Bool()
9696
setupCmdNoLogin = setupCmd.Flag("no-login", "Don't login after setting up").Bool()
97+
setupCmdToken = setupCmd.Flag("token", "Use token").String()
98+
setupCmdUsername = setupCmd.Flag("user", "The Username. Required if --token is set").String()
9799

98100
//
99101
// ---------> Config commands --------------------------------------

0 commit comments

Comments
 (0)