Skip to content

Conversation

@brandon1024
Copy link

@brandon1024 brandon1024 commented Nov 29, 2025

This revision tweaks the internals of the StringToString flag type to ensure that pointers are consistent across invocations of FlagSet.Parse(), Flag.Set(), FlagSet.GetStringToString().

Prior to this change, each call to GetStringToString would allocate and return a new map. Although this provides nice encapsulation, it means that users cannot manipulate the map (in tests, for instance). To address this, GetStringToString now returns the map directly from Flag.Value. Set() now avoids new allocations as well, updating the existing map over allocating new ones.

Documentation for all StringToString flags have been reworked for improved clarity. The tests for this flag type have been completely reworked. A small example demonstrating this flag type was also added.

Fixes #455
Fixes #457

@CLAassistant
Copy link

CLAassistant commented Nov 29, 2025

CLA assistant check
All committers have signed the CLA.

@brandon1024
Copy link
Author

/cc @tomasaschan 🚀

@brandon1024
Copy link
Author

Agh I just noticed that the other StringTo* flag types will also need to be patched. Perhaps I can address them in a seperate PR to avoid this ballooning into a huge patch.

This revision tweaks the internals of the StringToString flag type to
ensure that pointers are consistent across invocations of
FlagSet.Parse(), Flag.Set(), and FlagSet.GetStringToString().

Prior to this change, each call to GetStringToString would allocate and
return a new map. Although this provides nice encapsulation, it means
that users cannot manipulate the map (in tests, for instance). To
address this, GetStringToString now returns the map directly from
Flag.Value. Set() now avoids new allocations as well, updating the
existing map over allocating new ones.

Documentation for all StringToString flags have been reworked for
improved clarity. The tests for this flag type have been completely
reworked. A small example demonstrating this flag type was also added.
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.

resetting string-to-string flag to default state is not possible

2 participants