def UpdateMaskHook(ref, args, req):
  """Constructs updateMask for patch requests.

  This method works for Container and Function patch requests.

  Args:
    ref: A resource ref to the parsed Edge Container resource
    args: The parsed args namespace from CLI
    req: Created Patch request for the API call.

  Returns:
    Modified request for the API call.
  """
  del ref  # Unused.
  arg_name_to_field = {
      # Common flags
      '--input-topic': 'inputTopics',
      '--output-topic': 'outputTopics',
      '--description': 'description',
      # Container and Function flags
      '--memory': 'availableMemoryMb',
      '--volume-binding': 'volumeBindings',
      '--device-binding': 'deviceBindings',
      # Container flags
      '--docker-image': 'dockerImageUri',
      '--autostart': 'autostart',
      '--no-autostart': 'autostart',
      # Function flags
      '--source': 'dockerImageUri',
      '--timeout': 'requestTimeout',
      '--entry-point': 'entryPoint',
      '--function-type': 'functionType'
  }

  update_mask = []
  for arg_name in args.GetSpecifiedArgNames():
    if arg_name in arg_name_to_field:
      update_mask.append(arg_name_to_field[arg_name])
    elif 'env-var' in arg_name and 'environmentVariables' not in update_mask:
      update_mask.append('environmentVariables')

  req.updateMask = ','.join(update_mask)
  return req