mirror of
https://github.com/openharmony/third_party_libfuse.git
synced 2026-07-21 09:05:22 -04:00
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.
This commit is contained in:
+13
-2
@@ -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] <mountpoint>\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);
|
||||
|
||||
+12
-2
@@ -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] <mountpoint>\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;
|
||||
}
|
||||
|
||||
|
||||
+26
-4
@@ -273,6 +273,15 @@ static void* update_fs(void *data) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void show_help(const char *progname)
|
||||
{
|
||||
printf("usage: %s [options] <mountpoint>\n\n", progname);
|
||||
printf("File-system specific options:\n"
|
||||
" --update-interval=<secs> 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;
|
||||
}
|
||||
|
||||
+21
-2
@@ -319,6 +319,15 @@ static void* update_fs(void *data) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void show_help(const char *progname)
|
||||
{
|
||||
printf("usage: %s [options] <mountpoint>\n\n", progname);
|
||||
printf("File-system specific options:\n"
|
||||
" --update-interval=<secs> 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;
|
||||
}
|
||||
|
||||
|
||||
+22
-2
@@ -253,6 +253,16 @@ static void* update_fs(void *data) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void show_help(const char *progname)
|
||||
{
|
||||
printf("usage: %s [options] <mountpoint>\n\n", progname);
|
||||
printf("File-system specific options:\n"
|
||||
" --timeout=<secs> Timeout for kernel caches\n"
|
||||
" --update-interval=<secs> 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;
|
||||
}
|
||||
|
||||
|
||||
+13
-14
@@ -1599,6 +1599,12 @@ void fuse_lowlevel_help(void);
|
||||
*/
|
||||
void fuse_mount_help(void);
|
||||
|
||||
|
||||
/**
|
||||
* Print available options for `fuse_parse_cmdline()`.
|
||||
*/
|
||||
void fuse_cmdline_help(void);
|
||||
|
||||
/* ----------------------------------------------------------- *
|
||||
* Filesystem setup & teardown *
|
||||
* ----------------------------------------------------------- */
|
||||
@@ -1615,21 +1621,14 @@ struct fuse_cmdline_opts {
|
||||
|
||||
/**
|
||||
* Utility function to parse common options for simple file systems
|
||||
* using the low-level API. Available options are listed in `struct
|
||||
* fuse_opt fuse_helper_opts[]`. A single non-option argument is
|
||||
* treated as the mountpoint. Multiple (or no) non-option arguments
|
||||
* will result in an error.
|
||||
* using the low-level API. A help text that describes the available
|
||||
* options can be printed with `fuse_cmdline_help`. A single
|
||||
* non-option argument is treated as the mountpoint. Multiple
|
||||
* non-option arguments will result in an error.
|
||||
*
|
||||
* Unknown options are passed through unchanged. Known options (other
|
||||
* than --debug, which is preserved) and the mountpoint argument are
|
||||
* removed from *args*.
|
||||
*
|
||||
* If --help or --version is specified, the appropriate information is
|
||||
* printed to stdout and the function returns -1.
|
||||
*
|
||||
* If neither -o subtype= or -o fsname= options are given, the subtype
|
||||
* is set to the basename of the program (the fsname defaults to
|
||||
* "fuse").
|
||||
* If neither -o subtype= or -o fsname= options are given, a new
|
||||
* subtype option will be added and set to the basename of the program
|
||||
* (the fsname will remain unset, and then defaults to "fuse").
|
||||
*
|
||||
* @param args argument vector (input+output)
|
||||
* @param opts output argument for parsed options
|
||||
|
||||
@@ -127,6 +127,7 @@ FUSE_3.0 {
|
||||
fuse_lowlevel_help;
|
||||
fuse_lowlevel_version;
|
||||
fuse_mount_help;
|
||||
fuse_cmdline_help;
|
||||
fuse_mount_version;
|
||||
|
||||
local:
|
||||
|
||||
+3
-35
@@ -48,12 +48,7 @@ static const struct fuse_opt fuse_helper_opts[] = {
|
||||
FUSE_OPT_END
|
||||
};
|
||||
|
||||
static void usage(const char *progname)
|
||||
{
|
||||
printf("usage: %s mountpoint [options]\n\n", progname);
|
||||
}
|
||||
|
||||
static void helper_help(void)
|
||||
void fuse_cmdline_help(void)
|
||||
{
|
||||
printf("General options:\n"
|
||||
" -h --help print help\n"
|
||||
@@ -64,11 +59,6 @@ static void helper_help(void)
|
||||
"\n");
|
||||
}
|
||||
|
||||
static void helper_version(void)
|
||||
{
|
||||
printf("FUSE library version: %s\n", PACKAGE_VERSION);
|
||||
}
|
||||
|
||||
static int fuse_helper_opt_proc(void *data, const char *arg, int key,
|
||||
struct fuse_args *outargs)
|
||||
{
|
||||
@@ -126,27 +116,6 @@ int fuse_parse_cmdline(struct fuse_args *args,
|
||||
fuse_helper_opt_proc) == -1)
|
||||
return -1;
|
||||
|
||||
if (opts->show_version) {
|
||||
helper_version();
|
||||
fuse_lowlevel_version();
|
||||
fuse_mount_version();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (opts->show_help) {
|
||||
usage(args->argv[0]);
|
||||
helper_help();
|
||||
fuse_lowlevel_help();
|
||||
fuse_mount_help();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!opts->mountpoint) {
|
||||
fprintf(stderr, "error: no mountpoint specified\n");
|
||||
usage(args->argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If neither -o subtype nor -o fsname are specified,
|
||||
set subtype to program's basename */
|
||||
if (!opts->nodefault_subtype)
|
||||
@@ -225,7 +194,7 @@ int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
|
||||
return 1;
|
||||
|
||||
if (opts.show_version) {
|
||||
helper_version();
|
||||
printf("FUSE library version %s\n", PACKAGE_VERSION);
|
||||
fuse_lowlevel_version();
|
||||
fuse_mount_version();
|
||||
res = 0;
|
||||
@@ -235,7 +204,7 @@ int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
|
||||
/* Re-add --help for later processing by fuse_new()
|
||||
(that way we also get help for modules options) */
|
||||
if (opts.show_help) {
|
||||
helper_help();
|
||||
fuse_cmdline_help();
|
||||
if (fuse_opt_add_arg(&args, "--help") == -1) {
|
||||
res = 1;
|
||||
goto out1;
|
||||
@@ -245,7 +214,6 @@ int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
|
||||
if (!opts.show_help &&
|
||||
!opts.mountpoint) {
|
||||
fprintf(stderr, "error: no mountpoint specified\n");
|
||||
usage(args.argv[0]);
|
||||
res = 1;
|
||||
goto out1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user