@@ -30,6 +30,7 @@ pub(crate) struct OptionsCfg {
30
30
pub ( crate ) usage : Option < Box < Expr > > ,
31
31
pub ( crate ) version : Option < Box < Expr > > ,
32
32
pub ( crate ) max_width : Option < Box < Expr > > ,
33
+ pub ( crate ) fallback_usage : bool ,
33
34
}
34
35
35
36
#[ derive( Debug , Default ) ]
@@ -217,6 +218,15 @@ impl Parse for TopInfo {
217
218
boxed = true ;
218
219
} else if kw == "adjacent" {
219
220
adjacent = true ;
221
+ } else if kw == "fallback_to_usage" {
222
+ if let Some ( opts) = options. as_mut ( ) {
223
+ opts. fallback_usage = true ;
224
+ } else {
225
+ return Err ( Error :: new_spanned (
226
+ kw,
227
+ "This annotation only makes sense in combination with `options` or `command`" ,
228
+ ) ) ;
229
+ }
220
230
} else if kw == "short" {
221
231
let short = parse_arg ( input) ?;
222
232
with_command ( & kw, command. as_mut ( ) , |cfg| cfg. short . push ( short) ) ?;
@@ -338,6 +348,15 @@ impl Parse for Ed {
338
348
} else {
339
349
attrs. push ( EAttr :: UnitLong ( parse_opt_arg ( input) ?) ) ;
340
350
}
351
+ } else if kw == "fallback_to_usage" {
352
+ if matches ! ( mode, VariantMode :: Command ) {
353
+ attrs. push ( EAttr :: FallbackUsage ) ;
354
+ } else {
355
+ return Err ( Error :: new_spanned (
356
+ kw,
357
+ "In this context this attribute requires \" command\" annotation" ,
358
+ ) ) ;
359
+ }
341
360
} else if kw == "skip" {
342
361
skip = true ;
343
362
} else if kw == "adjacent" {
@@ -375,6 +394,7 @@ pub(crate) enum EAttr {
375
394
NamedCommand ( LitStr ) ,
376
395
UnnamedCommand ,
377
396
397
+ FallbackUsage ,
378
398
CommandShort ( LitChar ) ,
379
399
CommandLong ( LitStr ) ,
380
400
Adjacent ,
@@ -403,6 +423,8 @@ impl ToTokens for EAttr {
403
423
Self :: Usage ( u) => quote ! ( usage( #u) ) ,
404
424
Self :: Env ( e) => quote ! ( env( #e) ) ,
405
425
Self :: Hide => quote ! ( hide( ) ) ,
426
+ Self :: FallbackUsage => quote ! ( fallback_to_usage( ) ) ,
427
+
406
428
Self :: UnnamedCommand | Self :: UnitShort ( _) | Self :: UnitLong ( _) => unreachable ! ( ) ,
407
429
}
408
430
. to_tokens ( tokens) ;
0 commit comments