Unverified Commit 223046ec authored by guybe7's avatar guybe7 Committed by GitHub
Browse files

Repurpose redisCommandArg's name as the unique ID (#11051)

This PR makes sure that "name" is unique for all arguments in the same
level (i.e. all args of a command and all args within a block/oneof).
This means several argument with identical meaning can be referred to together,
but also if someone needs to refer to a specific one, they can use its full path.

In addition, the "display_text" field has been added, to be used by redis.io
in order to render the syntax of the command (for the vast majority it is
identical to "name" but sometimes we want to use a different string
that is not "name")
The "display" field is exposed via COMMAND DOCS and will be present
for every argument, except "oneof" and "block" (which are container
arguments)

Other changes:
1. Make sure we do not have any container arguments ("oneof" or "block")
   that contain less than two sub-args (otherwise it doesn't make sense)
2. migrate.json: both AUTH and AUTH2 should not be "optional"
3. arg names cannot contain underscores, and force the usage of hyphens
  (most of these were a result of the script that generated the initial json files
  from redis.io commands.json). 
parent fc3956e8
......@@ -104,6 +104,7 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
{
.name = "threshold",
.type = REDISMODULE_ARG_TYPE_STRING,
.display_text = "threshold" /* Just for coverage, doesn't have a visible effect */
},
{
.name = "count",
......@@ -116,11 +117,11 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
}
},
{
.name = "id_or_auto",
.name = "id-selector",
.type = REDISMODULE_ARG_TYPE_ONEOF,
.subargs = (RedisModuleCommandArg[]){
{
.name = "auto_id",
.name = "auto-id",
.type = REDISMODULE_ARG_TYPE_PURE_TOKEN,
.token = "*"
},
......@@ -132,7 +133,7 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
}
},
{
.name = "field_value",
.name = "data",
.type = REDISMODULE_ARG_TYPE_BLOCK,
.flags = REDISMODULE_CMD_ARG_MULTIPLE,
.subargs = (RedisModuleCommandArg[]){
......
......@@ -175,18 +175,36 @@ class KeySpec(object):
)
def verify_no_dup_names(container_fullname, args):
name_list = [arg.name for arg in args]
name_set = set(name_list)
if len(name_list) != len(name_set):
print("{}: Dup argument names: {}".format(container_fullname, name_list))
exit(1)
class Argument(object):
def __init__(self, parent_name, desc):
self.parent_name = parent_name
self.desc = desc
self.name = self.desc["name"].lower()
if "_" in self.name:
print("{}: name ({}) should not contain underscores".format(self.fullname(), self.name))
exit(1)
self.type = self.desc["type"]
self.key_spec_index = self.desc.get("key_spec_index", None)
self.parent_name = parent_name
self.subargs = []
self.subargs_name = None
if self.type in ["oneof", "block"]:
self.display = None
for subdesc in self.desc["arguments"]:
self.subargs.append(Argument(self.fullname(), subdesc))
if len(self.subargs) < 2:
print("{}: oneof or block arg contains less than two subargs".format(self.fullname()))
exit(1)
verify_no_dup_names(self.fullname(), self.subargs)
else:
self.display = self.desc.get("display")
def fullname(self):
return ("%s %s" % (self.parent_name, self.name)).replace("-", "_")
......@@ -226,6 +244,8 @@ class Argument(object):
)
if "deprecated_since" in self.desc:
s += ",.deprecated_since=\"%s\"" % self.desc["deprecated_since"]
if "display" in self.desc:
s += ",.display_text=\"%s\"" % self.desc["display"].lower()
if self.subargs:
s += ",.subargs=%s" % self.subarg_table_name()
......@@ -253,7 +273,9 @@ class Command(object):
self.subcommands = []
self.args = []
for arg_desc in self.desc.get("arguments", []):
self.args.append(Argument(self.fullname(), arg_desc))
arg = Argument(self.fullname(), arg_desc)
self.args.append(arg)
verify_no_dup_names(self.fullname(), self.args)
def fullname(self):
return self.name.replace("-", "_").replace(":", "")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment