Skip to content

Commit

Permalink
Minor improvements to point flags. Shows up properly in --help, adds …
Browse files Browse the repository at this point in the history
…a serializer, and accepts more of the define arguments.

PiperOrigin-RevId: 261707244
  • Loading branch information
tewalds committed Aug 15, 2019
1 parent 5736582 commit 0da4349
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pysc2/lib/point_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@

from pysc2.lib import point

# Let absl.flags know that DEFINE_point should show up in the caller's module.
flags.disclaim_key_flags()


class PointParser(flags.ArgumentParser):
"""Parse a flag into a point."""
"""Parse a flag into a pysc2.lib.point.Point."""

def parse(self, argument):
if not argument or argument == "0":
Expand All @@ -50,9 +53,17 @@ def parse(self, argument):
"Invalid point: '%s'. Valid: '<int>' or '<int>,<int>'." % argument)

def flag_type(self):
return "pysc2 point"
return "pysc2.lib.point.Point"


class PointSerializer(flags.ArgumentSerializer):
"""Custom serializer for pysc2.lib.point.Point."""

def serialize(self, value):
return str(value)


def DEFINE_point(name, default, help): # pylint: disable=invalid-name,redefined-builtin
def DEFINE_point(name, default, help_string, flag_values=flags.FLAGS, **args): # pylint: disable=invalid-name,redefined-builtin
"""Registers a flag whose value parses as a point."""
flags.DEFINE(PointParser(), name, default, help)
flags.DEFINE(PointParser(), name, default, help_string, flag_values,
PointSerializer(), **args)

0 comments on commit 0da4349

Please sign in to comment.