Skip to content

Conversation

@Tidwell
Copy link
Contributor

@Tidwell Tidwell commented Dec 10, 2025

Resolves #2594

Description:

  • Added an optional --maps flag to the map-generator that allows passing a subset of maps to process.
  • Updated README.md w/ documentation for using the new flag

Used the go/flag package.

Running without the flag, or with no arguments matches existing behavior of processing all the maps defined in main.go

go run .
go run . --maps=

New behavior is triggered to process a subset of maps by passing the --maps flag. Multiple maps are defined in a comma-separated list

go run . --maps=world,africa

Or a single map (useful for map development)

go run . --maps=fourislands

If an invalid map is passed, the process aborts and renders the error

go run . --maps=invalidmapname
Error generating terrain maps: map "invalidmapname" is not defined
exit status 1

By using the default flag package, we get --help for free:

go run . --help
Usage of <path-to-exe>/exe/map-generator:
  -maps string
    	optional comma-separated list of maps to process. ex: --maps=world,eastasia,big_plains

I do not write GO often. Gemini contributed to this syntax.

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory
  • I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced

Please put your Discord username so you can be contacted if a bug or regression is found:

tidwell

@Tidwell Tidwell requested a review from a team as a code owner December 10, 2025 05:50
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 10, 2025

Walkthrough

The changes introduce a new optional --maps CLI flag to the map-generator, enabling selective processing of specific maps instead of processing all maps by default. Documentation is added explaining the feature and providing usage examples.

Changes

Cohort / File(s) Summary
Documentation updates
map-generator/README.md
Added documentation explaining default map processing behavior and how to use the --maps flag to target specific maps with single and comma-separated examples.
CLI flag and map selection
map-generator/main.go
Introduced --maps optional CLI flag for selecting which maps to process. Added parseMapsFlag function to validate provided map names against available maps and return selected set. Integrated map selection into loadTerrainMaps to filter concurrent processing; updated main to parse flags and print success message.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Flag parsing and validation logic is straightforward and follows a clear pattern
  • Filtering integration into existing concurrent map processing is minimal
  • Focus areas: Verify parseMapsFlag validation logic handles edge cases (empty input, invalid names, duplicates), and confirm map filtering in loadTerrainMaps maintains concurrent processing correctness

Possibly related PRs

  • Fix uncompacted maps #2138 — Reorders the maps list in map-generator, which the new --maps flag validation logic depends on for determining available map names.

Suggested labels

Feature - Map

Suggested reviewers

  • evanpelle

Poem

🗺️ A flag to choose your maps with care,
No need to comment lines everywhere,
Selective builds for dev so fast,
The workflow loop will truly last! ✨

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a --maps flag to the map-generator for processing specific maps.
Description check ✅ Passed The description is detailed and directly related to the changeset, explaining the new flag functionality, usage examples, and how default behavior is preserved.
Linked Issues check ✅ Passed The PR fully addresses issue #2594 by implementing the --maps CLI flag, supporting single/multiple maps, preserving default behavior, and enabling focused map development.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the --maps flag feature: CLI flag parsing in main.go, validation logic, README documentation, and map selection integration.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
map-generator/main.go (1)

169-187: Trim whitespace from map names for better user experience.

The validation logic is correct, but users might naturally type --maps=world, africa with spaces after commas. Currently this would fail with map " africa" is not defined. While debuggable, trimming whitespace is a common courtesy in CLI tools.

Apply this diff to handle whitespace gracefully:

 func parseMapsFlag() (map[string]bool, error) {
 	if mapsFlag == "" {
 		return nil, nil
 	}
 
 	validNames := make(map[string]bool, len(maps))
 	for _, m := range maps {
 		validNames[m.Name] = true
 	}
 
 	selected := make(map[string]bool)
 	for _, name := range strings.Split(mapsFlag, ",") {
+		name = strings.TrimSpace(name)
+		if name == "" {
+			continue
+		}
 		if !validNames[name] {
 			return nil, fmt.Errorf("map %q is not defined", name)
 		}
 		selected[name] = true
 	}
 	return selected, nil
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2bfe245 and 859ab4f.

📒 Files selected for processing (2)
  • map-generator/README.md (1 hunks)
  • map-generator/main.go (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: VariableVince
Repo: openfrontio/OpenFrontIO PR: 1655
File: resources/maps/giantworldmap/manifest.json:165-174
Timestamp: 2025-07-31T12:03:08.052Z
Learning: In OpenFrontIO draft PRs, flag names in map manifest files may be placeholders that will be updated to match the actual SVG flag file names when the assets are received. The final naming depends on the actual flag SVG files provided, not code naming conventions.
🔇 Additional comments (7)
map-generator/main.go (6)

5-5: LGTM!

The standard library imports are appropriate for the new CLI flag functionality.

Also applies to: 10-10


14-14: LGTM!

Package-level variable follows standard Go flag package conventions.


190-193: LGTM!

The flag parsing and validation is correctly integrated at the start of processing, with proper error propagation.


199-201: LGTM!

The filter logic correctly preserves backward compatibility (process all when flag is omitted) while enabling selective processing when the flag is provided.


203-203: LGTM!

The loop variable capture is correct and prevents a common Go concurrency issue where goroutines would all reference the same variable.


227-228: LGTM!

The flag definition is clear with a helpful usage example, and parsing happens at the correct point before map processing.

map-generator/README.md (1)

20-28: LGTM!

The documentation clearly explains the new flag functionality with helpful examples for both single-map and multi-map scenarios. The examples correctly show comma-separated format without spaces.

Copy link
Collaborator

@evanpelle evanpelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@evanpelle evanpelle added this to the v28 milestone Dec 10, 2025
@evanpelle evanpelle merged commit afe072f into openfrontio:main Dec 10, 2025
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a --maps flag to the map-generator

2 participants