nfs4_getfacl: return 1 for unknown option and won't use '-?' anymore
Subsystems (2)
PATCH 1/2 nfs4_getfacl: return 1 for unknown option and won't use '-?' anymore
The getopt_long() function will return '?' if encounters an option character that was not in optstring. So it's impossible to tell the option '-?' from an unrecognized option. Don't mention it in Usage.
Signed-off-by Yongcheng Yang <[email protected]>
--- nfs4_getfacl/nfs4_getfacl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
nfs4_getfacl/nfs4_getfacl.c +6 -2
@@ -88,10 +88,14 @@ int main(int argc, char **argv)case 'c' : ignore_comment =1 ;break ; -default : +case 'h' :usage (1 ); res =0 ; goto out; +case '?' : +default : +usage (0 ); + goto out; } }
@@ -131,7 +135,7 @@ static void usage(int label) {if (label)fprintf (stderr,"%s %s -- get NFSv4 file or directory access control lists.\n" , execname,VERSION ); -fprintf (stderr,"Usage: %s [-R] file ...\n -H, --more-help\tdisplay ACL format information\n -?, -h, --help\tdisplay this help text\n -R --recursive\trecurse into subdirectories\n -c, --omit-header\tDo not display the comment header (Do not print filename)\n" , execname); +fprintf (stderr,"Usage: %s [-R] file ...\n -H, --more-help\tdisplay ACL format information\n -h, --help\tdisplay this help text\n -R --recursive\trecurse into subdirectories\n -c, --omit-header\tDo not display the comment header (Do not print filename)\n" , execname); }static void more_help ()
Signature · 1 line
2.20.1
PATCH 2/2 nfs4_getfacl: revise the Usage format as new options added
Signed-off-by Yongcheng Yang <[email protected]>
--- nfs4_getfacl/nfs4_getfacl.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
nfs4_getfacl/nfs4_getfacl.c +10 -1
@@ -135,7 +135,16 @@ static void usage(int label) {if (label)fprintf (stderr,"%s %s -- get NFSv4 file or directory access control lists.\n" , execname,VERSION ); -fprintf (stderr,"Usage: %s [-R] file ...\n -H, --more-help\tdisplay ACL format information\n -h, --help\tdisplay this help text\n -R --recursive\trecurse into subdirectories\n -c, --omit-header\tDo not display the comment header (Do not print filename)\n" , execname); + +static const char *gfusage = \ +"Usage: %s [OPTIONS] file ...\n" +" .. where OPTIONS is any (or none) of:\n" +" -H, --more-help display ACL format information\n" +" -h, --help display this help text\n" +" -R, --recursive recurse into subdirectories\n" +" -c, --omit-header Do not display the comment header (Do not print filename)\n" ; + +fprintf (stderr, gfusage, execname); }static void more_help ()
Signature · 1 line
2.20.1
Quoted 3 lines · Yongcheng Yang
The
getopt_long()function will return '?' if encounters an option character that was not in optstring. So it's impossible to tell the option '-?' from an unrecognized option. Don't mention it in Usage.
Thanks, both patches applied.--b.
Quoted 37 lines
Signed-off-by Yongcheng Yang <[email protected]>--- nfs4_getfacl/nfs4_getfacl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)nfs4_getfacl/nfs4_getfacl.c +6
-2@@ -88,10 +88,14 @@ int main(int argc, char **argv)case 'c' : ignore_comment =1 ;break ; -default : +case 'h' :usage (1 ); res =0 ; goto out; +case '?' : +default : +usage (0 ); + goto out; } }@@ -131,7 +135,7 @@ static void usage(int label) {if (label)fprintf (stderr,"%s %s -- get NFSv4 file or directory access control lists.\n" , execname,VERSION ); -fprintf (stderr,"Usage: %s [-R] file ...\n -H, --more-help\tdisplay ACL format information\n -?, -h, --help\tdisplay this help text\n -R --recursive\trecurse into subdirectories\n -c, --omit-header\tDo not display the comment header (Do not print filename)\n" , execname); +fprintf (stderr,"Usage: %s [-R] file ...\n -H, --more-help\tdisplay ACL format information\n -h, --help\tdisplay this help text\n -R --recursive\trecurse into subdirectories\n -c, --omit-header\tDo not display the comment header (Do not print filename)\n" , execname); }static void more_help ()Signature · 1 line
2.20.1