From 225c12aebf2d2f27e1d032d6b2149c7bb1d63506 Mon Sep 17 00:00:00 2001 From: Nikolaus Rath Date: Sun, 9 Oct 2016 17:08:29 -0700 Subject: fuse_parse_cmdline(): do not print help/version text The current behavior makes it difficult to add help for additional options. With the change, this becomes a lot easier. --- example/fuse_lo-plus.c | 15 +++++++++++++-- example/hello_ll.c | 14 ++++++++++++-- example/timefs1.c | 30 ++++++++++++++++++++++++++---- example/timefs2.c | 23 +++++++++++++++++++++-- example/timefs3.c | 24 ++++++++++++++++++++++-- 5 files changed, 94 insertions(+), 12 deletions(-) (limited to 'example') diff --git a/example/fuse_lo-plus.c b/example/fuse_lo-plus.c index 60c2daf..c27f377 100644 --- a/example/fuse_lo-plus.c +++ b/example/fuse_lo-plus.c @@ -452,10 +452,21 @@ int main(int argc, char *argv[]) if (fuse_parse_cmdline(&args, &opts) != 0) return 1; - if (opts.show_help || opts.show_version) { - ret = 1; + if (opts.show_help) { + printf("usage: %s [options] \n\n", argv[0]); + fuse_cmdline_help(); + fuse_lowlevel_help(); + fuse_mount_help(); + ret = 0; + goto err_out1; + } else if (opts.show_version) { + printf("FUSE library version %s\n", fuse_pkgversion()); + fuse_lowlevel_version(); + fuse_mount_version(); + ret = 0; goto err_out1; } + lo.debug = opts.debug; lo.root.next = lo.root.prev = &lo.root; lo.root.fd = open("/", O_PATH); diff --git a/example/hello_ll.c b/example/hello_ll.c index 014b8ca..b830cb2 100644 --- a/example/hello_ll.c +++ b/example/hello_ll.c @@ -192,8 +192,18 @@ int main(int argc, char *argv[]) if (fuse_parse_cmdline(&args, &opts) != 0) return 1; - if (opts.show_help || opts.show_version) { - ret = 1; + if (opts.show_help) { + printf("usage: %s [options] \n\n", argv[0]); + fuse_cmdline_help(); + fuse_lowlevel_help(); + fuse_mount_help(); + ret = 0; + goto err_out1; + } else if (opts.show_version) { + printf("FUSE library version %s\n", fuse_pkgversion()); + fuse_lowlevel_version(); + fuse_mount_version(); + ret = 0; goto err_out1; } diff --git a/example/timefs1.c b/example/timefs1.c index cff9545..430e00f 100644 --- a/example/timefs1.c +++ b/example/timefs1.c @@ -273,6 +273,15 @@ static void* update_fs(void *data) { return NULL; } +static void show_help(const char *progname) +{ + printf("usage: %s [options] \n\n", progname); + printf("File-system specific options:\n" + " --update-interval= Update-rate of file system contents\n" + " --no-notify Disable kernel notifications\n" + "\n"); +} + int main(int argc, char *argv[]) { struct fuse_args args = FUSE_ARGS_INIT(argc, argv); struct fuse_session *se; @@ -284,13 +293,26 @@ int main(int argc, char *argv[]) { opt_proc) == -1) return 1; - if (fuse_parse_cmdline(&args, &opts) != 0) - return 1; - if (opts.show_help || opts.show_version) { + if (fuse_parse_cmdline(&args, &opts) != 0) { ret = 1; goto err_out1; } + if (opts.show_help) { + show_help(argv[0]); + fuse_cmdline_help(); + fuse_lowlevel_help(); + fuse_mount_help(); + ret = 0; + goto err_out1; + } else if (opts.show_version) { + printf("FUSE library version %s\n", fuse_pkgversion()); + fuse_lowlevel_version(); + fuse_mount_version(); + ret = 0; + goto err_out1; + } + se = fuse_session_new(&args, &tfs_oper, sizeof(tfs_oper), NULL); if (se == NULL) @@ -324,8 +346,8 @@ err_out3: err_out2: fuse_session_destroy(se); err_out1: - free(opts.mountpoint); fuse_opt_free_args(&args); + free(opts.mountpoint); return ret ? 1 : 0; } diff --git a/example/timefs2.c b/example/timefs2.c index 3194230..ea10cc1 100644 --- a/example/timefs2.c +++ b/example/timefs2.c @@ -319,6 +319,15 @@ static void* update_fs(void *data) { return NULL; } +static void show_help(const char *progname) +{ + printf("usage: %s [options] \n\n", progname); + printf("File-system specific options:\n" + " --update-interval= Update-rate of file system contents\n" + " --no-notify Disable kernel notifications\n" + "\n"); +} + int main(int argc, char *argv[]) { struct fuse_args args = FUSE_ARGS_INIT(argc, argv); struct fuse_session *se; @@ -332,8 +341,18 @@ int main(int argc, char *argv[]) { if (fuse_parse_cmdline(&args, &opts) != 0) return 1; - if (opts.show_help || opts.show_version) { - ret = 1; + if (opts.show_help) { + show_help(argv[0]); + fuse_cmdline_help(); + fuse_lowlevel_help(); + fuse_mount_help(); + ret = 0; + goto err_out1; + } else if (opts.show_version) { + printf("FUSE library version %s\n", fuse_pkgversion()); + fuse_lowlevel_version(); + fuse_mount_version(); + ret = 0; goto err_out1; } diff --git a/example/timefs3.c b/example/timefs3.c index 0a52e0f..c04b81c 100644 --- a/example/timefs3.c +++ b/example/timefs3.c @@ -253,6 +253,16 @@ static void* update_fs(void *data) { return NULL; } +static void show_help(const char *progname) +{ + printf("usage: %s [options] \n\n", progname); + printf("File-system specific options:\n" + " --timeout= Timeout for kernel caches\n" + " --update-interval= Update-rate of file system contents\n" + " --no-notify Disable kernel notifications\n" + "\n"); +} + int main(int argc, char *argv[]) { struct fuse_args args = FUSE_ARGS_INIT(argc, argv); struct fuse_session *se; @@ -266,8 +276,18 @@ int main(int argc, char *argv[]) { if (fuse_parse_cmdline(&args, &opts) != 0) return 1; - if (opts.show_help || opts.show_version) { - ret = 1; + if (opts.show_help) { + show_help(argv[0]); + fuse_cmdline_help(); + fuse_lowlevel_help(); + fuse_mount_help(); + ret = 0; + goto err_out1; + } else if (opts.show_version) { + printf("FUSE library version %s\n", fuse_pkgversion()); + fuse_lowlevel_version(); + fuse_mount_version(); + ret = 0; goto err_out1; } -- cgit v1.2.3