1717 * and Technology (RIST). All rights reserved.
1818 * Copyright (c) 2016-2020 Intel, Inc. All rights reserved.
1919 * Copyright (c) 2017 IBM Corporation. All rights reserved.
20- * Copyright (c) 2021-2024 Nanook Consulting All rights reserved.
20+ * Copyright (c) 2021-2025 Nanook Consulting All rights reserved.
2121 * $COPYRIGHT$
2222 *
2323 * Additional copyrights may follow
@@ -130,7 +130,6 @@ int pmix_cmd_line_parse(char **pargv, char *shorts,
130130 break ;
131131 }
132132 opt = getopt_long (argc , argv , shorts , myoptions , & option_index );
133-
134133 switch (opt ) {
135134 case 0 :
136135 /* if this is an MCA param of some type, store it */
@@ -144,7 +143,21 @@ int pmix_cmd_line_parse(char **pargv, char *shorts,
144143 ++ optind ;
145144 break ;
146145 }
147- /* store actual option */
146+ // if this is a "-env" option, then there can be three entries
147+ // that describe what to do
148+ if (0 == strcmp (myoptions [option_index ].name , PMIX_CLI_PREPEND_ENVAR ) ||
149+ 0 == strcmp (myoptions [option_index ].name , PMIX_CLI_APPEND_ENVAR )) {
150+ mystore (myoptions [option_index ].name , argv [optind - 1 ], results );
151+ mystore (myoptions [option_index ].name , argv [optind ], results );
152+ ++ optind ;
153+ break ;
154+ }
155+ if (0 == strcmp (myoptions [option_index ].name , PMIX_CLI_UNSET_ENVAR )) {
156+ // unset-env option only takes one argument
157+ mystore (myoptions [option_index ].name , optarg , results );
158+ break ;
159+ }
160+ /* otherwise, store actual option */
148161 mystore (myoptions [option_index ].name , optarg , results );
149162 break ;
150163 case 'h' :
@@ -162,7 +175,8 @@ int pmix_cmd_line_parse(char **pargv, char *shorts,
162175 if (0 == strcmp (ptr , "version" ) || 0 == strcmp (ptr , "V" )) {
163176 str = pmix_show_help_string ("help-cli.txt" , "version" , false);
164177 if (NULL != str ) {
165- printf ("%s" , str );
178+ fprintf (stderr , "%s" , str );
179+ fflush (stderr );
166180 free (str );
167181 }
168182 PMIx_Argv_free (argv );
@@ -171,7 +185,8 @@ int pmix_cmd_line_parse(char **pargv, char *shorts,
171185 if (0 == strcmp (ptr , "verbose" ) || 0 == strcmp (ptr , "v" )) {
172186 str = pmix_show_help_string ("help-cli.txt" , "verbose" , false);
173187 if (NULL != str ) {
174- printf ("%s" , str );
188+ fprintf (stderr , "%s" , str );
189+ fflush (stderr );
175190 free (str );
176191 }
177192 PMIx_Argv_free (argv );
@@ -185,7 +200,8 @@ int pmix_cmd_line_parse(char **pargv, char *shorts,
185200 pmix_tool_basename , pmix_tool_basename ,
186201 pmix_tool_basename , pmix_tool_basename );
187202 if (NULL != str ) {
188- printf ("%s" , str );
203+ fprintf (stderr , "%s" , str );
204+ fflush (stderr );
189205 free (str );
190206 }
191207 PMIx_Argv_free (argv );
@@ -198,11 +214,13 @@ int pmix_cmd_line_parse(char **pargv, char *shorts,
198214 str = pmix_show_help_string ("help-cli.txt" , "unknown-option" , true,
199215 ptr , pmix_tool_basename );
200216 if (NULL != str ) {
201- printf ("%s" , str );
217+ fprintf (stderr , "%s" , str );
218+ fflush (stderr );
202219 free (str );
203220 }
204221 } else {
205- printf ("%s" , str );
222+ fprintf (stderr , "%s" , str );
223+ fflush (stderr );
206224 free (str );
207225 }
208226 PMIx_Argv_free (argv );
@@ -215,7 +233,8 @@ int pmix_cmd_line_parse(char **pargv, char *shorts,
215233 pmix_tool_basename ,
216234 pmix_tool_msg );
217235 if (NULL != str ) {
218- printf ("%s" , str );
236+ fprintf (stderr , "%s" , str );
237+ fflush (stderr );
219238 free (str );
220239 }
221240 PMIx_Argv_free (argv );
@@ -224,7 +243,8 @@ int pmix_cmd_line_parse(char **pargv, char *shorts,
224243 str = pmix_show_help_string ("help-cli.txt" , "unrecognized-option" , true,
225244 pmix_tool_basename , optarg );
226245 if (NULL != str ) {
227- printf ("%s" , str );
246+ fprintf (stderr , "%s" , str );
247+ fflush (stderr );
228248 free (str );
229249 }
230250 }
@@ -236,7 +256,8 @@ int pmix_cmd_line_parse(char **pargv, char *shorts,
236256 pmix_tool_version ,
237257 pmix_tool_msg );
238258 if (NULL != str ) {
239- printf ("%s" , str );
259+ fprintf (stderr , "%s" , str );
260+ fflush (stderr );
240261 free (str );
241262 }
242263 // if they ask for the version, that is all we do
@@ -302,7 +323,8 @@ int pmix_cmd_line_parse(char **pargv, char *shorts,
302323 str = pmix_show_help_string ("help-cli.txt" , "short-arg-error" , true,
303324 pmix_tool_basename , shorts [n ], ptr );
304325 if (NULL != str ) {
305- printf ("%s" , str );
326+ fprintf (stderr , "%s" , str );
327+ fflush (stderr );
306328 free (str );
307329 }
308330 PMIx_Argv_free (argv );
@@ -339,7 +361,8 @@ int pmix_cmd_line_parse(char **pargv, char *shorts,
339361 str = pmix_show_help_string ("help-cli.txt" , "short-no-long" , true,
340362 pmix_tool_basename , shorts [n ]);
341363 if (NULL != str ) {
342- printf ("%s" , str );
364+ fprintf (stderr , "%s" , str );
365+ fflush (stderr );
343366 free (str );
344367 }
345368 PMIx_Argv_free (argv );
@@ -362,7 +385,8 @@ int pmix_cmd_line_parse(char **pargv, char *shorts,
362385 pmix_tool_basename , argv [optind - 1 ],
363386 pmix_tool_basename , & argv [optind - 1 ][2 ]);
364387 if (NULL != str ) {
365- printf ("%s" , str );
388+ fprintf (stderr , "%s" , str );
389+ fflush (stderr );
366390 free (str );
367391 }
368392 PMIx_Argv_free (argv );
@@ -381,7 +405,8 @@ int pmix_cmd_line_parse(char **pargv, char *shorts,
381405 str = pmix_show_help_string ("help-cli.txt" , "unregistered-option" , true,
382406 pmix_tool_basename , argv [optind - 1 ], pmix_tool_basename );
383407 if (NULL != str ) {
384- printf ("%s" , str );
408+ fprintf (stderr , "%s" , str );
409+ fflush (stderr );
385410 free (str );
386411 }
387412 PMIx_Argv_free (argv );
0 commit comments