@@ -415,7 +415,7 @@ def colors_of(key: str) -> Tuple[str, str, List[str]]:
415415 return (color , on_color , attrs )
416416
417417
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 :
419419 def emphasise_example (x : str ) -> str :
420420 # Use ANSI escapes to enable italics at the start and disable at the end
421421 # Also use the color yellow to differentiate from the default green
@@ -479,11 +479,10 @@ def emphasise_example(x: str) -> str:
479479 line = line .replace (r'\}\}' , '__ESCAPED_CLOSE__' )
480480
481481 # 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 )
487486
488487 elements = [' ' * 2 * LEADING_SPACES_NUM ]
489488 for item in COMMAND_SPLIT_REGEX .split (line ):
@@ -640,23 +639,20 @@ def main() -> None:
640639 parser = create_parser ()
641640
642641 options = parser .parse_args ()
643- short = False
644- long = True
642+ display_option_length = "long"
645643 if not (options .short_options or options .long_options ):
646644 if os .environ .get ('TLDR_OPTIONS' ) == "short" :
647- short = True
648- long = False
645+ display_option_length = "short"
649646 elif os .environ .get ('TLDR_OPTIONS' ) == "long" :
650- short = False
651- long = True
647+ display_option_length = "long"
652648 elif os .environ .get ('TLDR_OPTIONS' ) == "both" :
653- short = True
654- long = True
649+ display_option_length = "both"
655650 if options .short_options :
656- short = True
657- long = False
651+ display_option_length = "short"
658652 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"
660656 colorama .init (strip = options .color )
661657 if options .color is False :
662658 os .environ ["FORCE_COLOR" ] = "true"
@@ -675,8 +671,7 @@ def main() -> None:
675671 if file_path .exists ():
676672 with file_path .open (encoding = 'utf-8' ) as open_file :
677673 output (open_file .read ().encode ('utf-8' ).splitlines (),
678- short ,
679- long ,
674+ display_option_length ,
680675 plain = options .markdown )
681676 elif options .search :
682677 search_term = options .search .lower ()
@@ -710,7 +705,7 @@ def main() -> None:
710705 " send a pull request to: https://github.com/tldr-pages/tldr"
711706 ).format (cmd = command ))
712707 else :
713- output (results [0 ][0 ], short , long , plain = options .markdown )
708+ output (results [0 ][0 ], display_option_length , plain = options .markdown )
714709 if results [1 :]:
715710 platforms_str = [result [1 ] for result in results [1 :]]
716711 are_multiple_platforms = len (platforms_str ) > 1
0 commit comments