[sheepdog] [PATCH v2 06/11] collie: show available command only for subcommand

Liu Yuan namei.unix at gmail.com
Mon May 27 08:22:58 CEST 2013


The new help usage tips would be:

yliu at K55VM-ubuntu:~/sheepdog$ collie/collie cluster
Available cluster commands:
  cluster info
  cluster format
  cluster shutdown
  cluster snapshot
  cluster recover

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 collie/collie.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/collie/collie.c b/collie/collie.c
index 574b93b..3c975ff 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -189,7 +189,7 @@ static unsigned long setup_commands(const struct command *commands,
 		usage(commands, EXIT_USAGE);
 	}
 
-	for (s = commands[i].sub; s->name; s++) {
+	for (s = commands[i].sub; subcmd && s->name; s++) {
 		if (!strcmp(s->name, subcmd)) {
 			command_fn = s->fn;
 			command_opts = s->opts;
@@ -202,7 +202,8 @@ static unsigned long setup_commands(const struct command *commands,
 	}
 
 	if (!command_fn) {
-		if (strcmp(subcmd, "help") && strcmp(subcmd, "--help"))
+		if (subcmd && strcmp(subcmd, "help") &&
+		    strcmp(subcmd, "--help"))
 			fprintf(stderr, "Invalid command '%s %s'\n", cmd, subcmd);
 		fprintf(stderr, "Available %s commands:\n", cmd);
 		for (s = commands[i].sub; s->name; s++)
@@ -343,7 +344,7 @@ int main(int argc, char **argv)
 
 	init_commands(&commands);
 
-	if (argc < 3)
+	if (argc < 2)
 		usage(commands, 0);
 
 	flags = setup_commands(commands, argv[1], argv[2]);
-- 
1.7.9.5




More information about the sheepdog mailing list