@@ -415,7 +415,7 @@ def colors_of(key: str) -> Tuple[str, str, List[str]]:
415
415
return (color , on_color , attrs )
416
416
417
417
418
- def output (page : str , short : bool , long : bool , plain : bool = False ) -> None :
418
+ def output (page : str , display_option_length : str , plain : bool = False ) -> None :
419
419
def emphasise_example (x : str ) -> str :
420
420
# Use ANSI escapes to enable italics at the start and disable at the end
421
421
# Also use the color yellow to differentiate from the default green
@@ -479,11 +479,10 @@ def emphasise_example(x: str) -> str:
479
479
line = line .replace (r'\}\}' , '__ESCAPED_CLOSE__' )
480
480
481
481
# Extract long or short options from placeholders
482
- if not (short and long ):
483
- if short :
484
- line = re .sub (r'{{\[([^|]+)\|[^|]+?\]}}' , r'\1' , line )
485
- elif long :
486
- line = re .sub (r'{{\[[^|]+\|([^|]+?)\]}}' , r'\1' , line )
482
+ if display_option_length == "short" :
483
+ line = re .sub (r'{{\[([^|]+)\|[^|]+?\]}}' , r'\1' , line )
484
+ elif display_option_length == "long" :
485
+ line = re .sub (r'{{\[[^|]+\|([^|]+?)\]}}' , r'\1' , line )
487
486
488
487
elements = [' ' * 2 * LEADING_SPACES_NUM ]
489
488
for item in COMMAND_SPLIT_REGEX .split (line ):
@@ -640,23 +639,20 @@ def main() -> None:
640
639
parser = create_parser ()
641
640
642
641
options = parser .parse_args ()
643
- short = False
644
- long = True
642
+ display_option_length = "long"
645
643
if not (options .short_options or options .long_options ):
646
644
if os .environ .get ('TLDR_OPTIONS' ) == "short" :
647
- short = True
648
- long = False
645
+ display_option_length = "short"
649
646
elif os .environ .get ('TLDR_OPTIONS' ) == "long" :
650
- short = False
651
- long = True
647
+ display_option_length = "long"
652
648
elif os .environ .get ('TLDR_OPTIONS' ) == "both" :
653
- short = True
654
- long = True
649
+ display_option_length = "both"
655
650
if options .short_options :
656
- short = True
657
- long = False
651
+ display_option_length = "short"
658
652
if options .long_options :
659
- long = True
653
+ display_option_length = "long"
654
+ if options .short_options and options .long_options :
655
+ display_option_length = "both"
660
656
colorama .init (strip = options .color )
661
657
if options .color is False :
662
658
os .environ ["FORCE_COLOR" ] = "true"
@@ -675,8 +671,7 @@ def main() -> None:
675
671
if file_path .exists ():
676
672
with file_path .open (encoding = 'utf-8' ) as open_file :
677
673
output (open_file .read ().encode ('utf-8' ).splitlines (),
678
- short ,
679
- long ,
674
+ display_option_length ,
680
675
plain = options .markdown )
681
676
elif options .search :
682
677
search_term = options .search .lower ()
@@ -710,7 +705,7 @@ def main() -> None:
710
705
" send a pull request to: https://github.com/tldr-pages/tldr"
711
706
).format (cmd = command ))
712
707
else :
713
- output (results [0 ][0 ], short , long , plain = options .markdown )
708
+ output (results [0 ][0 ], display_option_length , plain = options .markdown )
714
709
if results [1 :]:
715
710
platforms_str = [result [1 ] for result in results [1 :]]
716
711
are_multiple_platforms = len (platforms_str ) > 1
0 commit comments