commit 8b7978b114e5df89218daa9b4b48cc0e918ba917 Author: Sourabh Jain Date: Mon Feb 4 16:15:14 2019 +0530 lparstat: introduce the help command line option to print lparstat usage This patch adds a function to print the usage of lparstat. Also, a new element is added to structure option to handle long command line argument for help. Signed-off-by: Sourabh Jain Signed-off-by: Tyrel Datwyler diff --git a/man/lparstat.8 b/man/lparstat.8 index 9721580..467f570 100644 --- a/man/lparstat.8 +++ b/man/lparstat.8 @@ -9,8 +9,9 @@ .SH NAME lparstat \- Reports logical partition ( LPAR ) related information and statistics. .SH SYNOPSIS -.B /usr/sbin/lparstat -[ -i ] [ interval [ count ] ] +.B /usr/sbin/lparstat [ options ] +.HP +.B /usr/sbin/lparstat [ count ] .SH DESCRIPTION The \fIlparstat\fR command provides a report of LPAR related information and utilization statistics. This command provides a display of current LPAR related parameters and Hypervisor information, as well as utilization statistics for the LPAR. @@ -202,6 +203,17 @@ Desired Variable Capacity Weight The variable memory capacity weight of the LPAR. .TP .SH +.TP +\fB\-h, --help\fR +Display the usage of lparstat. +.RS +.SH +.TP +\fB\-V, --version\fR +Display the lparstat version information. +.RS +.SH +.TP interval The .B interval diff --git a/src/lparstat.c b/src/lparstat.c index c9b86fd..1abe54d 100644 --- a/src/lparstat.c +++ b/src/lparstat.c @@ -655,8 +655,20 @@ void print_default_output(int interval, int count) } while (--count > 0); } +static void usage(void) +{ + printf("Usage: lparstat [ options ]\n\tlparstat [ count ]\n\n" + "options:\n" + "\t-h, --help Show this message and exit.\n" + "\t-V, --version \tDisplay lparstat version information.\n" + "\t-i Lists details on the LPAR configuration.\n" + "interval The interval parameter specifies the amount of time between each report.\n" + "count The count parameter specifies how many reports will be displayed.\n"); +} + static struct option long_opts[] = { {"version", no_argument, NULL, 'V'}, + {"help", no_argument, NULL, 'h'}, {0, 0, 0, 0}, }; @@ -672,7 +684,7 @@ int main(int argc, char *argv[]) exit(1); } - while ((c = getopt_long(argc, argv, "iV", + while ((c = getopt_long(argc, argv, "iVh", long_opts, &opt_index)) != -1) { switch(c) { case 'i': @@ -681,7 +693,12 @@ int main(int argc, char *argv[]) case 'V': printf("lparstat - %s\n", VERSION); return 0; + case 'h': + usage(); + return 0; case '?': + usage(); + return 1; default: break; }