Move version and config out to early bails
This commit is contained in:
parent
073f8846aa
commit
996970fd81
1 changed files with 16 additions and 14 deletions
|
@ -92,6 +92,16 @@ func InnerMain(command string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Early bails
|
||||||
|
switch command {
|
||||||
|
case "version":
|
||||||
|
fmt.Println(version.Version)
|
||||||
|
return nil
|
||||||
|
case "config":
|
||||||
|
fmt.Printf("host: %s\taccount: %s\n", config.Host, config.Accounts[config.Host])
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// If there's a host set on the command line, override the one in the config
|
// If there's a host set on the command line, override the one in the config
|
||||||
if len(*host) != 0 {
|
if len(*host) != 0 {
|
||||||
config.Host = *host
|
config.Host = *host
|
||||||
|
@ -111,14 +121,8 @@ func InnerMain(command string) error {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// Grab the account
|
|
||||||
var account = config.Accounts[config.Host]
|
|
||||||
|
|
||||||
// Handle all the commands
|
// Handle all the commands
|
||||||
switch command {
|
switch command {
|
||||||
case "version":
|
|
||||||
fmt.Println(version.Version)
|
|
||||||
|
|
||||||
case "status":
|
case "status":
|
||||||
response, err := client.Status(ctx, &rove.StatusRequest{})
|
response, err := client.Status(ctx, &rove.StatusRequest{})
|
||||||
switch {
|
switch {
|
||||||
|
@ -151,7 +155,7 @@ func InnerMain(command string) error {
|
||||||
|
|
||||||
case "move":
|
case "move":
|
||||||
d := rove.CommandsRequest{
|
d := rove.CommandsRequest{
|
||||||
Account: account,
|
Account: config.Accounts[config.Host],
|
||||||
Commands: []*rove.Command{
|
Commands: []*rove.Command{
|
||||||
{
|
{
|
||||||
Command: game.CommandMove,
|
Command: game.CommandMove,
|
||||||
|
@ -161,7 +165,7 @@ func InnerMain(command string) error {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := verifyID(account); err != nil {
|
if err := verifyID(d.Account); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,8 +179,8 @@ func InnerMain(command string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
case "radar":
|
case "radar":
|
||||||
dat := rove.RadarRequest{Account: account}
|
dat := rove.RadarRequest{Account: config.Accounts[config.Host]}
|
||||||
if err := verifyID(account); err != nil {
|
if err := verifyID(dat.Account); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,8 +195,8 @@ func InnerMain(command string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
case "rover":
|
case "rover":
|
||||||
req := rove.RoverRequest{Account: account}
|
req := rove.RoverRequest{Account: config.Accounts[config.Host]}
|
||||||
if err := verifyID(account); err != nil {
|
if err := verifyID(req.Account); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
response, err := client.Rover(ctx, &req)
|
response, err := client.Rover(ctx, &req)
|
||||||
|
@ -204,8 +208,6 @@ func InnerMain(command string) error {
|
||||||
default:
|
default:
|
||||||
fmt.Printf("attributes: %+v\n", response)
|
fmt.Printf("attributes: %+v\n", response)
|
||||||
}
|
}
|
||||||
case "config":
|
|
||||||
fmt.Printf("host: %s\taccount: %s\n", config.Host, account)
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Print the usage
|
// Print the usage
|
||||||
|
|
Loading…
Add table
Reference in a new issue