Add broadcast command to the cmdline client
This commit is contained in:
parent
db19e4a657
commit
091469dd91
2 changed files with 16 additions and 0 deletions
|
@ -40,6 +40,7 @@ func printUsage() {
|
|||
fmt.Fprintln(os.Stderr, "\tstash stores the object at the rover location in the inventory")
|
||||
fmt.Fprintln(os.Stderr, "\trepair uses an inventory object to repair the rover")
|
||||
fmt.Fprintln(os.Stderr, "\trecharge wait a tick to recharge the rover")
|
||||
fmt.Fprintln(os.Stderr, "\tbroadcast MSG broadcast a simple ASCII triplet to nearby rovers")
|
||||
fmt.Fprintln(os.Stderr, "\nEnvironment")
|
||||
fmt.Fprintln(os.Stderr, "\tROVE_USER_DATA path to user data, defaults to "+defaultDataPath)
|
||||
}
|
||||
|
@ -225,6 +226,19 @@ func InnerMain(command string, args ...string) error {
|
|||
Bearing: args[i],
|
||||
},
|
||||
)
|
||||
case "broadcast":
|
||||
i++
|
||||
if len(args) == i {
|
||||
return fmt.Errorf("broadcast command must be passed an ASCII triplet")
|
||||
} else if len(args[i]) > 3 {
|
||||
return fmt.Errorf("broadcast command must be given ASCII triplet of 3 or less: %s", args[i])
|
||||
}
|
||||
commands = append(commands,
|
||||
&rove.Command{
|
||||
Command: game.CommandBroadcast,
|
||||
Message: []byte(args[i]),
|
||||
},
|
||||
)
|
||||
default:
|
||||
// By default just use the command literally
|
||||
commands = append(commands,
|
||||
|
|
|
@ -53,7 +53,9 @@ func Test_InnerMain(t *testing.T) {
|
|||
assert.NoError(t, InnerMain("command", "move", "N"))
|
||||
assert.NoError(t, InnerMain("command", "stash"))
|
||||
assert.NoError(t, InnerMain("command", "repair"))
|
||||
assert.NoError(t, InnerMain("command", "broadcast", "abc"))
|
||||
|
||||
// Give it malformed commands
|
||||
assert.Error(t, InnerMain("command", "move", "stash"))
|
||||
assert.Error(t, InnerMain("command", "broadcast"))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue