@@ -305,14 +305,17 @@ int adopt_usage_fprint(
305
305
const adopt_spec specs [])
306
306
{
307
307
const adopt_spec * spec ;
308
- int choice = 0 ;
308
+ int choice = 0 , next_choice = 0 , optional = 0 ;
309
309
int error ;
310
310
311
311
if ((error = fprintf (file , "usage: %s" , command )) < 0 )
312
312
goto done ;
313
313
314
314
for (spec = specs ; spec -> type ; ++ spec ) {
315
- int optional = !(spec -> usage & ADOPT_USAGE_REQUIRED );
315
+ if (!choice )
316
+ optional = !(spec -> usage & ADOPT_USAGE_REQUIRED );
317
+
318
+ next_choice = !!((spec + 1 )-> usage & ADOPT_USAGE_CHOICE );
316
319
317
320
if (spec -> usage & ADOPT_USAGE_HIDDEN )
318
321
continue ;
@@ -326,6 +329,11 @@ int adopt_usage_fprint(
326
329
goto done ;
327
330
328
331
if (optional && !choice && (error = fprintf (file , "[" )) < 0 )
332
+ error = fprintf (file , "[" );
333
+ if (!optional && !choice && next_choice )
334
+ error = fprintf (file , "(" );
335
+
336
+ if (error < 0 )
329
337
goto done ;
330
338
331
339
if (spec -> type == ADOPT_VALUE && spec -> alias )
@@ -350,10 +358,15 @@ int adopt_usage_fprint(
350
358
if (error < 0 )
351
359
goto done ;
352
360
353
- choice = !!((spec + 1 )-> usage & ADOPT_USAGE_CHOICE );
361
+ if (!optional && choice && !next_choice )
362
+ error = fprintf (file , ")" );
363
+ else if (optional && !next_choice )
364
+ error = fprintf (file , "]" );
354
365
355
- if (optional && ! choice && ( error = fprintf ( file , "]" )) < 0 )
366
+ if (error < 0 )
356
367
goto done ;
368
+
369
+ choice = next_choice ;
357
370
}
358
371
359
372
error = fprintf (file , "\n" );
0 commit comments