Add the upgrade command to the cmdline client
This commit is contained in:
parent
804f82dd20
commit
35b25dde98
2 changed files with 25 additions and 0 deletions
|
@ -44,6 +44,7 @@ func printUsage() {
|
||||||
fmt.Fprintln(os.Stderr, "\tbroadcast MSG broadcast a simple ASCII triplet to nearby rovers")
|
fmt.Fprintln(os.Stderr, "\tbroadcast MSG broadcast a simple ASCII triplet to nearby rovers")
|
||||||
fmt.Fprintln(os.Stderr, "\tsalvage salvages a dormant rover for parts")
|
fmt.Fprintln(os.Stderr, "\tsalvage salvages a dormant rover for parts")
|
||||||
fmt.Fprintln(os.Stderr, "\ttransfer transfer's control into a dormant rover")
|
fmt.Fprintln(os.Stderr, "\ttransfer transfer's control into a dormant rover")
|
||||||
|
fmt.Fprintln(os.Stderr, "\tupgrade SPEC spends rover parts to upgrade one rover spec (capacity, range, integrity, charge")
|
||||||
fmt.Fprintln(os.Stderr, "\twait waits before performing the next command")
|
fmt.Fprintln(os.Stderr, "\twait waits before performing the next command")
|
||||||
fmt.Fprintf(os.Stderr, "\n")
|
fmt.Fprintf(os.Stderr, "\n")
|
||||||
fmt.Fprintln(os.Stderr, "Environment")
|
fmt.Fprintln(os.Stderr, "Environment")
|
||||||
|
@ -274,6 +275,28 @@ func InnerMain(command string, args ...string) error {
|
||||||
Command: roveapi.CommandType_broadcast,
|
Command: roveapi.CommandType_broadcast,
|
||||||
Data: []byte(args[i]),
|
Data: []byte(args[i]),
|
||||||
}
|
}
|
||||||
|
case "upgrade":
|
||||||
|
i++
|
||||||
|
if len(args) == i {
|
||||||
|
return fmt.Errorf("upgrade command must be passed a spec to upgrade")
|
||||||
|
}
|
||||||
|
var u roveapi.RoverUpgrade
|
||||||
|
switch args[i] {
|
||||||
|
case "capacity":
|
||||||
|
u = roveapi.RoverUpgrade_Capacity
|
||||||
|
case "range":
|
||||||
|
u = roveapi.RoverUpgrade_Range
|
||||||
|
case "integrity":
|
||||||
|
u = roveapi.RoverUpgrade_MaximumIntegrity
|
||||||
|
case "charge":
|
||||||
|
u = roveapi.RoverUpgrade_MaximumCharge
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("upgrade command must be passed a known upgrade spec")
|
||||||
|
}
|
||||||
|
cmd = &roveapi.Command{
|
||||||
|
Command: roveapi.CommandType_upgrade,
|
||||||
|
Upgrade: u,
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
// By default just use the command literally
|
// By default just use the command literally
|
||||||
cmd = &roveapi.Command{
|
cmd = &roveapi.Command{
|
||||||
|
|
|
@ -54,6 +54,7 @@ func Test_InnerMain(t *testing.T) {
|
||||||
assert.NoError(t, InnerMain("command", "toggle"))
|
assert.NoError(t, InnerMain("command", "toggle"))
|
||||||
assert.NoError(t, InnerMain("command", "stash"))
|
assert.NoError(t, InnerMain("command", "stash"))
|
||||||
assert.NoError(t, InnerMain("command", "repair"))
|
assert.NoError(t, InnerMain("command", "repair"))
|
||||||
|
assert.NoError(t, InnerMain("command", "upgrade", "capacity"))
|
||||||
assert.NoError(t, InnerMain("command", "broadcast", "abc"))
|
assert.NoError(t, InnerMain("command", "broadcast", "abc"))
|
||||||
assert.NoError(t, InnerMain("command", "wait", "10"))
|
assert.NoError(t, InnerMain("command", "wait", "10"))
|
||||||
assert.NoError(t, InnerMain("command", "wait", "1", "turn", "NW", "toggle", "broadcast", "zyx"))
|
assert.NoError(t, InnerMain("command", "wait", "1", "turn", "NW", "toggle", "broadcast", "zyx"))
|
||||||
|
@ -61,5 +62,6 @@ func Test_InnerMain(t *testing.T) {
|
||||||
// Give it malformed commands
|
// Give it malformed commands
|
||||||
assert.Error(t, InnerMain("command", "unknown"))
|
assert.Error(t, InnerMain("command", "unknown"))
|
||||||
assert.Error(t, InnerMain("command", "broadcast"))
|
assert.Error(t, InnerMain("command", "broadcast"))
|
||||||
|
assert.Error(t, InnerMain("command", "upgrade"))
|
||||||
assert.Error(t, InnerMain("command", "1"))
|
assert.Error(t, InnerMain("command", "1"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue