[sheepdog] [PATCH] collie: print subcommand usage when function return EXIT_USAGE

Kai Zhang kyle at zelin.io
Wed May 15 14:26:13 CEST 2013


Output before:
$collie vdi create test
Please specify the VDI size

Output after:
$collie vdi create test
Please specify the VDI size
Usage: collie vdi create [-P] [-c copies] [-a address] [-p port] [-h] <vdiname> <size>
Options:
-P, --prealloc          preallocate all the data objects
-c, --copies            specify the data redundancy (number of copies)
-a, --address           specify the daemon address (default: localhost)
-p, --port              specify the daemon port
-h, --help              display this help and exit

Signed-off-by: Kai Zhang <kyle at zelin.io>
---
 collie/collie.c |    5 ++++-
 collie/common.c |    5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/collie/collie.c b/collie/collie.c
index 05031fd..574b93b 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -408,5 +408,8 @@ int main(int argc, char **argv)
 		exit(EXIT_SYSFAIL);
 	}
 
-	return command_fn(argc, argv);
+	ret = command_fn(argc, argv);
+	if (ret == EXIT_USAGE)
+		subcommand_usage(argv[1], argv[2], EXIT_USAGE);
+	return ret;
 }
diff --git a/collie/common.c b/collie/common.c
index 0646587..57d70e0 100644
--- a/collie/common.c
+++ b/collie/common.c
@@ -228,7 +228,10 @@ int do_generic_subcommand(struct subcommand *sub, int argc, char **argv)
 			    && argc != 5)
 				subcommand_usage(argv[1], argv[2], EXIT_USAGE);
 			optind++;
-			return sub[i].fn(argc, argv);
+			ret = sub[i].fn(argc, argv);
+			if (ret == EXIT_USAGE)
+				subcommand_usage(argv[1], argv[2], EXIT_USAGE);
+			return ret;
 		}
 	}
 
-- 
1.7.1




More information about the sheepdog mailing list