Commit d561f1ca authored by Alvaro Herrera's avatar Alvaro Herrera

pgbench: accept unambiguous builtin prefixes for -b

This makes it easier to use "-b se" instead of typing the full "-b
select-only".

Author: Fabien Coelho
Reviewed-by: Michaël Paquier
parent 2c83f435
...@@ -269,6 +269,7 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</> ...@@ -269,6 +269,7 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
Add the specified builtin script to the list of executed scripts. Add the specified builtin script to the list of executed scripts.
Available builtin scripts are: <literal>tpcb-like</>, Available builtin scripts are: <literal>tpcb-like</>,
<literal>simple-update</> and <literal>select-only</>. <literal>simple-update</> and <literal>select-only</>.
Unambiguous prefixes of builtin names are accepted.
With special name <literal>list</>, show the list of builtin scripts With special name <literal>list</>, show the list of builtin scripts
and exit immediately. and exit immediately.
</para> </para>
......
...@@ -2746,22 +2746,36 @@ listAvailableScripts(void) ...@@ -2746,22 +2746,36 @@ listAvailableScripts(void)
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
/* return builtin script "name" if unambiguous */
static char * static char *
findBuiltin(const char *name, char **desc) findBuiltin(const char *name, char **desc)
{ {
int i; int i,
found = 0,
len = strlen(name);
char *commands = NULL;
for (i = 0; i < N_BUILTIN; i++) for (i = 0; i < N_BUILTIN; i++)
{ {
if (strncmp(builtin_script[i].name, name, if (strncmp(builtin_script[i].name, name, len) == 0)
strlen(builtin_script[i].name)) == 0)
{ {
*desc = builtin_script[i].desc; *desc = builtin_script[i].desc;
return builtin_script[i].commands; commands = builtin_script[i].commands;
found++;
} }
} }
fprintf(stderr, "no builtin script found for name \"%s\"\n", name); /* ok, unambiguous result */
if (found == 1)
return commands;
/* error cases */
if (found == 0)
fprintf(stderr, "no builtin script found for name \"%s\"\n", name);
else /* found > 1 */
fprintf(stderr,
"ambiguous builtin name: %d builtin scripts found for prefix \"%s\"\n", found, name);
listAvailableScripts(); listAvailableScripts();
exit(1); exit(1);
} }
......
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