text: from pystachio import Ref
  
  class ParseError(Exception):
    pass
  
  def add_port_to(option_name):
    def add_port_callback(option, opt, value, parser):
      if not getattr(parser.values, option_name, None):
        setattr(parser.values, option_name, {})
      try:
        name, port = value.split(':')
      except (ValueError, TypeError):
        raise ParseError('Invalid value for %s: %s should be of form NAME:PORT' % (
          opt, value))
      try:
        port = int(port)
      except ValueError:
        raise ParseError('Port does not appear to be an integer: %s' % port)
      getattr(parser.values, option_name)[name] = port
    return add_port_callback
  
  def add_binding_to(option_name):
    def add_binding_callback(option, opt, value, parser):
      if not getattr(parser.values, option_name, None):
        setattr(parser.values, option_name, [])
      if len(value.split('=')) != 2:
        raise ParseError('Binding must be of the form NAME=VALUE')
      name, value = value.split('=')
      try:
        ref = Ref.from_address(name)
      except Ref.InvalidRefError as e:
        raise ParseError('Could not parse ref %s: %s' % (name, e))
      getattr(parser.values, option_name).append({ref: value})
    return add_binding_callback
  