gfs2-utils: master - gfs2l: Improve usage message and opt handling
Andrew Price
andyp at fedoraproject.org
Mon May 20 13:46:57 UTC 2013
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=cc0a456dd650c793e4ebce10b0bb7c7ff5048a90
Commit: cc0a456dd650c793e4ebce10b0bb7c7ff5048a90
Parent: 65ddd7e85220b9c3a295c45cb1bb3dc175f45d3c
Author: Andrew Price <anprice at redhat.com>
AuthorDate: Fri May 17 22:20:25 2013 +0100
Committer: Andrew Price <anprice at redhat.com>
CommitterDate: Fri May 17 22:20:25 2013 +0100
gfs2l: Improve usage message and opt handling
Tweak the usage message and add a help option to print it on demand.
Signed-off-by: Andrew Price <anprice at redhat.com>
---
gfs2/libgfs2/gfs2l.c | 21 +++++++++++++++++----
1 files 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);
More information about the cluster-commits
mailing list