From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 2/7] gfs2l: Improve usage message and opt handling
Date: Mon, 20 May 2013 12:37:11 +0100 [thread overview]
Message-ID: <1369049836-8204-2-git-send-email-anprice@redhat.com> (raw)
In-Reply-To: <1369049836-8204-1-git-send-email-anprice@redhat.com>
Tweak the usage message and add a help option to print it on demand.
Signed-off-by: Andrew Price <anprice@redhat.com>
---
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 <script_path> <fs_path>\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] <fs_path>\n", cmd);
+ printf("Available options:\n");
+ printf(" -h Print this help message and exit\n");
+ printf(" -f <script_path> 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
next prev parent reply other threads:[~2013-05-20 11:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-20 11:37 [Cluster-devel] [PATCH 1/7] gfs2-utils build: Fix reporting lack of check Andrew Price
2013-05-20 11:37 ` Andrew Price [this message]
2013-05-20 11:37 ` [Cluster-devel] [PATCH 3/7] gfs2l: Enable setting the type of a block Andrew Price
2013-05-20 11:37 ` [Cluster-devel] [PATCH 4/7] gfs2l: Add hash comments Andrew Price
2013-05-20 11:37 ` [Cluster-devel] [PATCH 5/7] gfs2l: Add options to print block types and fields Andrew Price
2013-05-20 11:37 ` [Cluster-devel] [PATCH 6/7] gfs2l: Read from stdin by default Andrew Price
2013-05-20 11:37 ` [Cluster-devel] [PATCH 7/7] gfs2l: Improve grammar layout and path parsing Andrew Price
2013-05-20 12:08 ` [Cluster-devel] [PATCH 1/7] gfs2-utils build: Fix reporting lack of check Steven Whitehouse
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1369049836-8204-2-git-send-email-anprice@redhat.com \
--to=anprice@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).