[sheepdog] [PATCH v3] dog: permit two or more depth of subcommands
Hitoshi Mitake
mitake.hitoshi at gmail.com
Wed Nov 13 13:59:41 CET 2013
Current dog command dies when user invokes "dog node log level set" without any
arguments because of its subcommand design. This patch removes this limitation.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
v3: declare the depth as a static variable
v2: define do_generic_subcommand() as a macro for a common case (depth == 0)
dog/common.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/dog/common.c b/dog/common.c
index 4480b99..8c9b326 100644
--- a/dog/common.c
+++ b/dog/common.c
@@ -227,7 +227,9 @@ int send_light_req(const struct node_id *nid, struct sd_req *hdr)
int do_generic_subcommand(struct subcommand *sub, int argc, char **argv)
{
int i, ret;
+ static int depth = -1;
+ depth++;
for (i = 0; sub[i].name; i++) {
if (!strcmp(sub[i].name, argv[optind])) {
unsigned long flags = sub[i].flags;
@@ -240,7 +242,7 @@ int do_generic_subcommand(struct subcommand *sub, int argc, char **argv)
}
}
- if (flags & CMD_NEED_ARG && argc < 5)
+ if (flags & CMD_NEED_ARG && argc < 5 + depth)
subcommand_usage(argv[1], argv[2], EXIT_USAGE);
optind++;
ret = sub[i].fn(argc, argv);
@@ -250,6 +252,7 @@ int do_generic_subcommand(struct subcommand *sub, int argc, char **argv)
}
}
+ depth--;
subcommand_usage(argv[1], argv[2], EXIT_FAILURE);
return EXIT_FAILURE;
}
--
1.8.1.2
More information about the sheepdog
mailing list