Merge pull request #17 from mdiluz/add-broadcast-to-cmdline

Add broadcast command to the cmdline client
This commit is contained in:
Marc Di Luzio 2020-07-09 22:44:51 +01:00 committed by GitHub
commit 23764a3fc3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View file

@ -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,

View file

@ -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"))
}