add 'map' cli command to provide map information (#100)

* add 'map' cli command

- provides the following map information functions:
  - list all available maps in the global registry
  - display map metadata

- update docs with map command examples

* add list and info subcommands to map cli command

* rename map command list and info factory functions

* add --all flag to map info subcommand

* handle cmd.Help error
This commit is contained in:
Blayne Campbell 2022-08-09 16:06:28 -06:00 committed by GitHub
parent 91106aec09
commit ffeb401377
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 177 additions and 0 deletions

View file

@ -2,6 +2,7 @@ package maps
import (
"fmt"
"sort"
"github.com/BattlesnakeOfficial/rules"
)
@ -21,6 +22,16 @@ func (registry MapRegistry) RegisterMap(id string, m GameMap) {
registry[id] = m
}
// List returns all registered map IDs in alphabetical order
func (registry MapRegistry) List() []string {
var keys []string
for k, _ := range registry {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}
// GetMap returns the map associated with the given ID.
func (registry MapRegistry) GetMap(id string) (GameMap, error) {
if m, ok := registry[id]; ok {
@ -34,6 +45,11 @@ func GetMap(id string) (GameMap, error) {
return globalRegistry.GetMap(id)
}
// List returns a list of maps registered to the global registry.
func List() []string {
return globalRegistry.List()
}
// RegisterMap adds a map to the global registry.
func RegisterMap(id string, m GameMap) {
globalRegistry.RegisterMap(id, m)