I'm writing FUSE filesystem which uses some arguments. I'd like to pass all unrecognized options to FUSE (because it has its own options). Can I do that using argp
or getopt
? For now both give me "Unknown option" error.
Asked
Active
Viewed 909 times
0

Lapsio
- 6,384
- 4
- 20
- 26
-
1The difficulty with parsing (and passing) unknown options on to FUSE is that you don't know whether the options take arguments or not, so you don't know how to continue parsing accurately. There could also be problems with bunched options (`ls -ltr` has a bunched set of options in the `-ltr`; it could also be written `ls -l -t -r` and would have the same effect). A lot depends on the rules that are already in effect. – Jonathan Leffler May 02 '18 at 01:47
1 Answers
1
Argp
From the "Argp Flags" section of the documentation:
ARGP_NO_ERRS
Don't print error messages for unknown options to stderr; unless this flag is set,
ARGP_PARSE_ARGV0
is ignored, asargv[0]
is used as the program name in the error messages. This flag impliesARGP_NO_EXIT
. This is based on the assumption that silent exiting upon errors is bad behavior.
Getopt
For getopt
(as well as getopt_long
and getopt_long_only
), you simply set the global variable opterr
to 0 before calling the function. Alternatively, you can use a short option string with a leading :
character as in ":o:v"
to handle -o output-file
and -v
(:
will be returned if -o
is missing its argument and ?
if any option that does not exist in your option string is found).