Skip to content

Commit 5d99ef6

Browse files
committed
Set display with options
1 parent 9926aff commit 5d99ef6

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

tldr.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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, plain: bool = False, longform: bool = True, shortform: bool = True) -> None:
418+
def output(page: str, short: bool, long: bool, 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,10 +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 (shortform and longform):
483-
if shortform:
482+
if not (short and long):
483+
if short:
484484
line = re.sub(r'{{(-[^|]+)\|--[^|]+?}}', r'{{\1}}', line)
485-
elif longform:
485+
elif long:
486486
line = re.sub(r'{{-[^|]+\|(--[^|]+?)}}', r'{{\1}}', line)
487487

488488
elements = [' ' * 2 * LEADING_SPACES_NUM]
@@ -610,6 +610,18 @@ def create_parser() -> ArgumentParser:
610610
action='store_true',
611611
help='Just print the plain page file.')
612612

613+
parser.add_argument('-V', '--longform',
614+
default=False,
615+
action="store_true",
616+
help='Display longform options over shortform',
617+
)
618+
619+
parser.add_argument('-S', '--shortform',
620+
default=False,
621+
action="store_true",
622+
help='Display shortform options over longform',
623+
)
624+
613625
parser.add_argument(
614626
'command', type=str, nargs='*', help="command to lookup", metavar='command'
615627
).complete = {"bash": "shtab_tldr_cmd_list", "zsh": "shtab_tldr_cmd_list"}
@@ -631,6 +643,8 @@ def main() -> None:
631643

632644
options = parser.parse_args()
633645

646+
short=options.shortform
647+
long=options.longform
634648
colorama.init(strip=options.color)
635649
if options.color is False:
636650
os.environ["FORCE_COLOR"] = "true"
@@ -682,7 +696,7 @@ def main() -> None:
682696
" send a pull request to: https://github.com/tldr-pages/tldr"
683697
).format(cmd=command))
684698
else:
685-
output(results[0][0], plain=options.markdown)
699+
output(results[0][0], short, long, plain=options.markdown)
686700
if results[1:]:
687701
platforms_str = [result[1] for result in results[1:]]
688702
are_multiple_platforms = len(platforms_str) > 1

0 commit comments

Comments
 (0)