From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Price Date: Mon, 20 May 2013 12:37:11 +0100 Subject: [Cluster-devel] [PATCH 2/7] gfs2l: Improve usage message and opt handling In-Reply-To: <1369049836-8204-1-git-send-email-anprice@redhat.com> References: <1369049836-8204-1-git-send-email-anprice@redhat.com> Message-ID: <1369049836-8204-2-git-send-email-anprice@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Tweak the usage message and add a help option to print it on demand. Signed-off-by: Andrew Price --- gfs2/libgfs2/gfs2l.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/gfs2/libgfs2/gfs2l.c b/gfs2/libgfs2/gfs2l.c index 2eacb2d..50ddb82 100644 --- a/gfs2/libgfs2/gfs2l.c +++ b/gfs2/libgfs2/gfs2l.c @@ -5,19 +5,23 @@ static void usage(const char *cmd) { - fprintf(stderr, "Usage: %s -f \n", cmd); - fprintf(stderr, "Use -f - for stdin\n"); + printf("A language for modifying and querying a gfs2 file system.\n"); + printf("Usage: %s [options] \n", cmd); + printf("Available options:\n"); + printf(" -h Print this help message and exit\n"); + printf(" -f Path to script file or '-' for stdin\n"); } struct cmdopts { char *fspath; FILE *src; + unsigned help:1; }; static int getopts(int argc, char *argv[], struct cmdopts *opts) { int opt; - while ((opt = getopt(argc, argv, "f:")) != -1) { + while ((opt = getopt(argc, argv, "f:h")) != -1) { switch (opt) { case 'f': if (!strcmp("-", optarg)) { @@ -30,14 +34,18 @@ static int getopts(int argc, char *argv[], struct cmdopts *opts) } } break; + case 'h': + opts->help = 1; + return 0; default: - usage(argv[0]); + fprintf(stderr, "Use -h for help\n"); return 1; } } if (argc - optind != 1) { usage(argv[0]); + fprintf(stderr, "Missing file system path. Use -h for help.\n"); return 1; } @@ -106,6 +114,11 @@ int main(int argc, char *argv[]) exit(1); } + if (opts.help) { + usage(argv[0]); + exit(0); + } + sdp = openfs(argv[optind]); if (sdp == NULL) { exit(1); -- 1.8.1.4