* [PATCH] smbinfo: Improve help usage and add -h option.
@ 2019-04-17 10:06 Kenneth D'souza
2019-04-18 18:29 ` Pavel Shilovsky
0 siblings, 1 reply; 2+ messages in thread
From: Kenneth D'souza @ 2019-04-17 10:06 UTC (permalink / raw)
To: linux-cifs; +Cc: piastryyy
Call usage only for -h case. This avoids cluttering the screen with long
help output.
As we are adding more options to the utility, the end error is just hidden.
Call short_usage wherever necessary.
Signed-off-by: Kenneth D'souza <kdsouza@redhat.com>
---
smbinfo.c | 27 ++++++++++++++++++++++-----
smbinfo.rst | 5 ++++-
2 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/smbinfo.c b/smbinfo.c
index 4bc503a..8c8f43f 100644
--- a/smbinfo.c
+++ b/smbinfo.c
@@ -64,6 +64,8 @@ usage(char *name)
{
fprintf(stderr, "Usage: %s [-V] <command> <file>\n"
"-V for verbose output\n"
+ "-h display this help text\n"
+ "-v print smbinfo version\n"
"Commands are\n"
" fileaccessinfo:\n"
" Prints FileAccessInfo for a cifs file.\n"
@@ -97,6 +99,14 @@ usage(char *name)
exit(1);
}
+static void
+short_usage(char *name)
+{
+ fprintf(stderr, "Usage: %s [-v] [-V] <command> <file>\n"
+ "Try 'smbinfo -h' for more information.\n", name);
+ exit(1);
+}
+
static void
win_to_timeval(uint64_t smb2_time, struct timeval *tv)
{
@@ -1075,7 +1085,11 @@ int main(int argc, char *argv[])
int c;
int f;
- while ((c = getopt_long(argc, argv, "vV", NULL, NULL)) != -1) {
+ if (argc < 2) {
+ short_usage(argv[0]);
+ }
+
+ while ((c = getopt_long(argc, argv, "vVh", NULL, NULL)) != -1) {
switch (c) {
case 'v':
printf("smbinfo version %s\n", VERSION);
@@ -1083,15 +1097,18 @@ int main(int argc, char *argv[])
case 'V':
verbose = 1;
break;
- default:
+ case 'h':
usage(argv[0]);
+ break;
+ default:
+ short_usage(argv[0]);
}
}
- if (optind >= argc - 1)
- usage(argv[0]);
+ if (optind >= argc -1)
+ short_usage(argv[0]);
- if ((f = open(argv[optind + 1], O_RDONLY)) < 0) {
+ if ((f = open(argv[optind + 1 ], O_RDONLY)) < 0) {
fprintf(stderr, "Failed to open %s\n", argv[optind + 1]);
exit(1);
}
diff --git a/smbinfo.rst b/smbinfo.rst
index 0c96050..be4c829 100644
--- a/smbinfo.rst
+++ b/smbinfo.rst
@@ -11,7 +11,7 @@ Userspace helper to display SMB-specific file information for the Linux SMB clie
SYNOPSIS
********
- smbinfo [-v] [-V] {command} {file system object}
+ smbinfo [-v] [-h] [-V] {command} {file system object}
***********
DESCRIPTION
@@ -38,6 +38,9 @@ OPTIONS
-V
Verbose output.
+-h
+ Print help explaining the command line options.
+
*******
COMMAND
*******
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] smbinfo: Improve help usage and add -h option.
2019-04-17 10:06 [PATCH] smbinfo: Improve help usage and add -h option Kenneth D'souza
@ 2019-04-18 18:29 ` Pavel Shilovsky
0 siblings, 0 replies; 2+ messages in thread
From: Pavel Shilovsky @ 2019-04-18 18:29 UTC (permalink / raw)
To: Kenneth D'souza; +Cc: linux-cifs
ср, 17 апр. 2019 г. в 03:06, Kenneth D'souza <kdsouza@redhat.com>:
>
> Call usage only for -h case. This avoids cluttering the screen with long
> help output.
> As we are adding more options to the utility, the end error is just hidden.
> Call short_usage wherever necessary.
>
> Signed-off-by: Kenneth D'souza <kdsouza@redhat.com>
> ---
> smbinfo.c | 27 ++++++++++++++++++++++-----
> smbinfo.rst | 5 ++++-
> 2 files changed, 26 insertions(+), 6 deletions(-)
>
> diff --git a/smbinfo.c b/smbinfo.c
> index 4bc503a..8c8f43f 100644
> --- a/smbinfo.c
> +++ b/smbinfo.c
> @@ -64,6 +64,8 @@ usage(char *name)
> {
> fprintf(stderr, "Usage: %s [-V] <command> <file>\n"
> "-V for verbose output\n"
> + "-h display this help text\n"
> + "-v print smbinfo version\n"
> "Commands are\n"
> " fileaccessinfo:\n"
> " Prints FileAccessInfo for a cifs file.\n"
> @@ -97,6 +99,14 @@ usage(char *name)
> exit(1);
> }
>
> +static void
> +short_usage(char *name)
> +{
> + fprintf(stderr, "Usage: %s [-v] [-V] <command> <file>\n"
> + "Try 'smbinfo -h' for more information.\n", name);
> + exit(1);
> +}
> +
> static void
> win_to_timeval(uint64_t smb2_time, struct timeval *tv)
> {
> @@ -1075,7 +1085,11 @@ int main(int argc, char *argv[])
> int c;
> int f;
>
> - while ((c = getopt_long(argc, argv, "vV", NULL, NULL)) != -1) {
> + if (argc < 2) {
> + short_usage(argv[0]);
> + }
> +
> + while ((c = getopt_long(argc, argv, "vVh", NULL, NULL)) != -1) {
> switch (c) {
> case 'v':
> printf("smbinfo version %s\n", VERSION);
> @@ -1083,15 +1097,18 @@ int main(int argc, char *argv[])
> case 'V':
> verbose = 1;
> break;
> - default:
> + case 'h':
> usage(argv[0]);
> + break;
> + default:
> + short_usage(argv[0]);
> }
> }
>
> - if (optind >= argc - 1)
> - usage(argv[0]);
> + if (optind >= argc -1)
> + short_usage(argv[0]);
>
> - if ((f = open(argv[optind + 1], O_RDONLY)) < 0) {
> + if ((f = open(argv[optind + 1 ], O_RDONLY)) < 0) {
> fprintf(stderr, "Failed to open %s\n", argv[optind + 1]);
> exit(1);
> }
> diff --git a/smbinfo.rst b/smbinfo.rst
> index 0c96050..be4c829 100644
> --- a/smbinfo.rst
> +++ b/smbinfo.rst
> @@ -11,7 +11,7 @@ Userspace helper to display SMB-specific file information for the Linux SMB clie
> SYNOPSIS
> ********
>
> - smbinfo [-v] [-V] {command} {file system object}
> + smbinfo [-v] [-h] [-V] {command} {file system object}
>
> ***********
> DESCRIPTION
> @@ -38,6 +38,9 @@ OPTIONS
> -V
> Verbose output.
>
> +-h
> + Print help explaining the command line options.
> +
> *******
> COMMAND
> *******
> --
> 2.20.1
>
Merged, thanks.
--
Best regards,
Pavel Shilovsky
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-04-18 18:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-17 10:06 [PATCH] smbinfo: Improve help usage and add -h option Kenneth D'souza
2019-04-18 18:29 ` Pavel Shilovsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).