Skip to contentSkip to conversation

nfs4_getfacl: return 1 for unknown option and won't use '-?' anymore

PATCH In review Yongcheng Yang 2 participants 3 messages Jul 23, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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.

---
 nfs4_getfacl/nfs4_getfacl.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
nfs4_getfacl/nfs4_getfacl.c +6 -2
index 4df2b04..2f57866 100644
@@ -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
#1 lore raw

PATCH 2/2 nfs4_getfacl: revise the Usage format as new options added

---
 nfs4_getfacl/nfs4_getfacl.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
nfs4_getfacl/nfs4_getfacl.c +10 -1
index 2f57866..e068095 100644
@@ -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
#2 lore raw
In reply to Yongcheng Yang
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
---
 nfs4_getfacl/nfs4_getfacl.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
nfs4_getfacl/nfs4_getfacl.c +6 -2
index 4df2b04..2f57866 100644
@@ -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