def GetFlagName(attribute_name, presentation_name, flag_name_overrides=None, prefixes=False, is_anchor=False): """Gets the flag name for a given attribute name. Returns a flag name for an attribute, adding prefixes as necessary or using overrides if an override map is provided. Args: attribute_name: str, the name of the attribute to base the flag name on. presentation_name: str, the anchor argument name of the resource the attribute belongs to (e.g. '--foo'). flag_name_overrides: {str: str}, a dict of attribute names to exact string of the flag name to use for the attribute. None if no overrides. prefixes: bool, whether to use the resource name as a prefix for the flag. is_anchor: bool, True if this is the anchor flag, False otherwise. Returns: (str) the name of the flag. """ flag_name_overrides = flag_name_overrides or {} if attribute_name in flag_name_overrides: return flag_name_overrides.get(attribute_name) if is_anchor: return presentation_name if attribute_name == 'project': return '' if prefixes: return util.FlagNameFormat('-'.join( [presentation_name, attribute_name])) return util.FlagNameFormat(attribute_name)
def GetFlagName(attribute_name, presentation_name, flag_name_overrides=None, prefixes=False): """Gets the flag name for a given attribute name. Returns a flag name for an attribute, adding prefixes as necessary or using overrides if an override map is provided. Args: attribute_name: str, the name of the attribute to base the flag name on. presentation_name: str, the anchor argument name of the resource the attribute belongs to (e.g. '--foo'). flag_name_overrides: {str: str}, a dict of attribute names to exact string of the flag name to use for the attribute. None if no overrides. prefixes: bool, whether to use the resource name as a prefix for the flag. Returns: (str) the name of the flag. """ flag_name_overrides = flag_name_overrides or {} if attribute_name in flag_name_overrides: return flag_name_overrides.get(attribute_name) if attribute_name == 'project': return '' # If the presentation spec's overall name is the same as the attribute, # treat this attibute like an "anchor" in a resource argument. if (util.NormalizeFormat(presentation_name) == util.NormalizeFormat(attribute_name)): return presentation_name if prefixes: return util.FlagNameFormat('-'.join([presentation_name, attribute_name])) return util.FlagNameFormat(attribute_name)
def _FallthroughStringFromData(fallthrough_data): if fallthrough_data.get('is_positional', False): return resource_util.PositionalFormat(fallthrough_data['arg_name']) return resource_util.FlagNameFormat(fallthrough_data['arg_name'])