All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kenneth D'souza <kdsouza@redhat.com>
To: linux-cifs@vger.kernel.org
Cc: piastryyy@gmail.com, smfrench@gmail.com
Subject: [PATCH] getcifsacl: Improve help usage and add -h option.
Date: Thu, 21 Feb 2019 10:39:25 +0530	[thread overview]
Message-ID: <20190221050925.17643-1-kdsouza@redhat.com> (raw)

Call getcifsacl_usage only for -h and default case.
For others error out with appropriate message.

Signed-off-by: Kenneth D'souza <kdsouza@redhat.com>
---
 getcifsacl.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/getcifsacl.c b/getcifsacl.c
index 7f6e673..850a252 100644
--- a/getcifsacl.c
+++ b/getcifsacl.c
@@ -40,6 +40,7 @@
 
 static void *plugin_handle;
 static bool plugin_loaded;
+static char *execname;
 
 static void
 print_each_ace_mask(uint32_t mask)
@@ -331,6 +332,8 @@ getcifsacl_usage(const char *prog)
 		prog);
 	fprintf(stderr, "Usage: %s [option] <file_name>\n", prog);
 	fprintf(stderr, "Valid options:\n");
+	fprintf(stderr, "\t-h	Display this help text\n");
+	fprintf(stderr, "\n");
 	fprintf(stderr, "\t-v	Version of the program\n");
 	fprintf(stderr, "\n");
 	fprintf(stderr, "\t-r	Display raw values of the ACE fields\n");
@@ -345,8 +348,15 @@ main(const int argc, char *const argv[])
 	ssize_t attrlen;
 	size_t bufsize = BUFSIZE;
 	char *filename, *attrval;
+	execname = basename(argv[0]);
+
+        if (argc < 2) {
+                fprintf(stderr, "%s: you must specify a filename.\n", execname);
+                printf("Try `getcifsacl -h' for more information.\n");
+                goto out;
+        }
 
-	while ((c = getopt_long(argc, argv, "r:v", NULL, NULL)) != -1) {
+	while ((c = getopt_long(argc, argv, "rhv", NULL, NULL)) != -1) {
 		switch (c) {
 		case 'v':
 			printf("Version: %s\n", VERSION);
@@ -355,18 +365,18 @@ main(const int argc, char *const argv[])
 			raw = true;
 			break;
 		default:
-			break;
+			getcifsacl_usage(execname);
+                        goto out;
+
 		}
 	}
 
-	if (raw && argc == 3)
-		filename = argv[2];
-	else if (argc == 2)
-		filename = argv[1];
-	else {
-		getcifsacl_usage(basename(argv[0]));
-		goto out;
-	}
+        if (optind >= argc) {
+               printf("you must specify a filename after options.\n");
+               printf("Usage: getcifsacl [option] <file_name>\n");
+                goto out;
+        } else
+              filename= argv[optind];
 
 	if (!raw && !plugin_loaded) {
 		ret = init_plugin(&plugin_handle);
-- 
2.20.1


             reply	other threads:[~2019-02-21  5:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-21  5:09 Kenneth D'souza [this message]
2019-03-09  0:37 ` [PATCH] getcifsacl: Improve help usage and add -h option Pavel Shilovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190221050925.17643-1-kdsouza@redhat.com \
    --to=kdsouza@redhat.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=piastryyy@gmail.com \
    --cc=smfrench@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.