diff mbox series

[rt-tests,v3,28/33] pip_stress: Prepare arg parser to accept only long options

Message ID 20210320183829.1318-29-dwagner@suse.de
State New
Headers show
Series JSON cleanups and more tests updated | expand

Commit Message

Daniel Wagner March 20, 2021, 6:38 p.m. UTC
Introduce the option value enums to be able to parse only long
options.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 src/pi_tests/pip_stress.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

John Kacur May 7, 2021, 4:55 p.m. UTC | #1
On Sat, 20 Mar 2021, Daniel Wagner wrote:

> Introduce the option value enums to be able to parse only long

> options.

> 

> Signed-off-by: Daniel Wagner <dwagner@suse.de>

> ---

>  src/pi_tests/pip_stress.c | 11 ++++++++---

>  1 file changed, 8 insertions(+), 3 deletions(-)

> 

> diff --git a/src/pi_tests/pip_stress.c b/src/pi_tests/pip_stress.c

> index ed034799da66..0831f698ff1d 100644

> --- a/src/pi_tests/pip_stress.c

> +++ b/src/pi_tests/pip_stress.c

> @@ -77,6 +77,10 @@ static void usage(int error)

>  	exit(error);

>  }

>  

> +enum option_values {

> +	OPT_HELP=1

> +};

> +

>  int main(int argc, char *argv[])

>  {

>  	void *mptr;	/* memory pointer */

> @@ -87,14 +91,15 @@ int main(int argc, char *argv[])

>  

>  	for (;;) {

>  		struct option long_options[] = {

> -			{ "help",	no_argument,		NULL,	'h' },

> -			{ NULL,		0,			NULL,	0 },

> +			{"help",	no_argument,		NULL, OPT_HELP},

> +			{NULL,		0,			NULL, 0}

>  		};

>  

> -		int c = getopt_long(argc, argv, "s:h", long_options, NULL);

> +		int c = getopt_long(argc, argv, "h", long_options, NULL);

>  		if (c == -1)

>  			break;

>  		switch (c) {

> +		case OPT_HELP:

>  		case 'h':

>  			usage(0);

>  			break;

> -- 

> 2.30.2

> 

> 

Signed-off-by: John Kacur <jkacur@redhat.com>
diff mbox series

Patch

diff --git a/src/pi_tests/pip_stress.c b/src/pi_tests/pip_stress.c
index ed034799da66..0831f698ff1d 100644
--- a/src/pi_tests/pip_stress.c
+++ b/src/pi_tests/pip_stress.c
@@ -77,6 +77,10 @@  static void usage(int error)
 	exit(error);
 }
 
+enum option_values {
+	OPT_HELP=1
+};
+
 int main(int argc, char *argv[])
 {
 	void *mptr;	/* memory pointer */
@@ -87,14 +91,15 @@  int main(int argc, char *argv[])
 
 	for (;;) {
 		struct option long_options[] = {
-			{ "help",	no_argument,		NULL,	'h' },
-			{ NULL,		0,			NULL,	0 },
+			{"help",	no_argument,		NULL, OPT_HELP},
+			{NULL,		0,			NULL, 0}
 		};
 
-		int c = getopt_long(argc, argv, "s:h", long_options, NULL);
+		int c = getopt_long(argc, argv, "h", long_options, NULL);
 		if (c == -1)
 			break;
 		switch (c) {
+		case OPT_HELP:
 		case 'h':
 			usage(0);
 			break;