def AddMutexEnvVarsFlags(parser): """Add flags for creating updating and deleting env vars.""" # TODO(b/119837621): Use env_vars_util.AddUpdateEnvVarsFlags when # `gcloud run` supports an env var file. key_type = env_vars_util.EnvVarKeyType value_type = env_vars_util.EnvVarValueType flag_name = 'env-vars' long_name = 'environment variables' group = parser.add_mutually_exclusive_group() update_remove_group = group.add_argument_group(help=( 'Only --update-{0} and --remove-{0} can be used together. If both ' 'are specified, --remove-{0} will be applied first.' ).format(flag_name)) map_util.AddMapUpdateFlag(update_remove_group, flag_name, long_name, key_type=key_type, value_type=value_type) map_util.AddMapRemoveFlag(update_remove_group, flag_name, long_name, key_type=key_type) map_util.AddMapClearFlag(group, flag_name, long_name) map_util.AddMapSetFlag(group, flag_name, long_name, key_type=key_type, value_type=value_type)
def AddMapFlagsNoFile(parser, flag_name, group_help='', long_name=None, key_type=None, value_type=None): """Add flags like map_util.AddUpdateMapFlags but without the file one. Args: parser: The argument parser flag_name: The name for the property to be used in flag names group_help: Help text for the group of flags long_name: The name for the property to be used in help text key_type: A function to apply to map keys. value_type: A function to apply to map values. """ if not long_name: long_name = flag_name group = parser.add_mutually_exclusive_group(group_help) update_remove_group = group.add_argument_group( help=('Only --update-{0} and --remove-{0} can be used together. If both ' 'are specified, --remove-{0} will be applied first.' ).format(flag_name)) map_util.AddMapUpdateFlag( update_remove_group, flag_name, long_name, key_type=key_type, value_type=value_type) map_util.AddMapRemoveFlag( update_remove_group, flag_name, long_name, key_type=key_type) map_util.AddMapClearFlag(group, flag_name, long_name) map_util.AddMapSetFlag( group, flag_name, long_name, key_type=key_type, value_type=value_type)
def testMapSetFlag(self): """Standard --set-* invocation.""" map_util.AddMapSetFlag(self.parser, 'food-prices', 'prices of food items', None, int) args = self.parser.parse_args(['--set-food-prices=cod=12,tomato=2']) self.assertEqual(args.set_food_prices, _TEST_MAP)