Skip to content

Commit 3bc6ba4

Browse files
feat: add support for placeholder escaping, prep for release, misc (#247)
* feat: add support for placeholder escaping, prep for release, misc * docs: update CHANGELOG * chore: update README screenshot * docs: update README usage to align with actual usage (#248) --------- Signed-off-by: K.B.Dharun Krishna <[email protected]> Co-authored-by: Patrice Denis <[email protected]>
1 parent 5decc07 commit 3bc6ba4

File tree

10 files changed

+175
-32
lines changed

10 files changed

+175
-32
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ instance/
7070

7171
# Sphinx documentation
7272
docs/_build/
73-
docs/man
73+
docs/man/.doctrees
7474

7575
# PyBuilder
7676
.pybuilder/

CHANGELOG.md

+25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
# Changelog
22

3+
## 3.3.0 (06/29/2023)
4+
5+
## Breaking
6+
7+
* Drop support for EOL versions Python 3.6 and Python 3.7.
8+
9+
### Bugfixes
10+
11+
* Return `str` instead of `list` when executing `tldr -l` (thanks [@uunnxx](https://github.com/uunnxx))
12+
* Use pathlib instead of os.path (thanks [@vitorhcl](https://github.com/vitorhcl))
13+
* Respect language settings when geting a list of commands (thanks [@frenzymadness](https://github.com/frenzymadness))
14+
* Fix `--search` option (thanks [@CleanMachine1](https://github.com/CleanMachine1))
15+
16+
### Features
17+
18+
* Add support for BSD platform directories (thanks [@vitorhcl](https://github.com/vitorhcl))
19+
* Add `--update` long option (thanks [@owenvoke](https://github.com/owenvoke))
20+
* Add support for fetching individual translation archives for cache (thanks [@SaurabhDRao](https://github.com/SaurabhDRao))
21+
* Add support to show message for other versions of the same page in other platforms (thanks [@Jaimepas77](https://github.com/Jaimepas77))
22+
* Update `DOWNLOAD_CACHE_LOCATION` to use GitHub Releases (thanks [@vitorhcl](https://github.com/vitorhcl))
23+
* Add `macos` alias for `osx` directory and update `--platform` option (thanks [@patricedenis](https://github.com/patricedenis))
24+
* Add support for escaping placeholders for special pages (thanks [@kbdharun](https://github.com/kbdharun))
25+
* Add support for Python 3.11 and Python 3.12 (thanks [@kbdharun](https://github.com/kbdharun))
26+
* Add support for [Client Specification v2.2](https://github.com/tldr-pages/tldr/releases/tag/v2.2)
27+
328
## 3.2.0 (05/09/2023)
429

530
### Bugfixes

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 Felix Yan
3+
Copyright (c) 2014 Felix Yan and 2014-present tldr-pages contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
[![PyPI Release](https://img.shields.io/pypi/v/tldr.svg)](https://pypi.python.org/pypi/tldr)
44
[![Build](https://github.com/tldr-pages/tldr-python-client/workflows/Test/badge.svg?branch=main)](https://github.com/tldr-pages/tldr-python-client/actions?query=branch%3Amain)
5+
[![Snap Release](https://snapcraft.io/tldr/badge.svg)](https://snapcraft.io/tldr)
56

67
Python command-line client for [tldr pages](https://github.com/tldr-pages/tldr).
78

8-
![tldr pages example](https://raw.github.com/tldr-pages/tldr/main/images/tldr-dark.png)
9+
![Tldr Python client displaying the tar page](https://raw.github.com/tldr-pages/tldr-python-client/main/images/tldr-dark.png)
910

1011
## Installation
1112

@@ -42,7 +43,7 @@ sudo snap install tldr
4243

4344
## Usage
4445

45-
```
46+
```txt
4647
usage: tldr command [options]
4748
4849
Python command line client for tldr
@@ -57,7 +58,7 @@ options:
5758
-u, --update, --update_cache
5859
Update the local cache of pages and exit
5960
-p PLATFORM, --platform PLATFORM
60-
Override the operating system [linux, osx, sunos, windows, common]
61+
Override the operating system [android, freebsd, linux, netbsd, openbsd, osx, sunos, windows, common]
6162
-l, --list List all available commands for operating system
6263
-s SOURCE, --source SOURCE
6364
Override the default page source
@@ -92,13 +93,14 @@ export TLDR_DOWNLOAD_CACHE_LOCATION="https://tldr-pages.github.io/assets/tldr.zi
9293
Cache is downloaded from `TLDR_DOWNLOAD_CACHE_LOCATION` (defaults to the one described in [the client specification](https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#caching)), unzipped and extracted into the [local cache directory](#cache-location). Pages are loaded directly from `TLDR_PAGES_SOURCE_LOCATION` if `tldr <command>` is used.
9394

9495
- `TLDR_CACHE_ENABLED` (default is `1`):
95-
- If set to `1`, the client will first try to load from cache, and fall back to fetching from the internet if the cache doesn't exist or is too old.
96-
- If set to `0`, the client will fetch from the internet, and fall back to the cache if the page cannot be fetched from the internet.
96+
- If set to `1`, the client will first try to load from cache, and fall back to fetching from the internet if the cache doesn't exist or is too old.
97+
- If set to `0`, the client will fetch from the internet, and fall back to the cache if the page cannot be fetched from the internet.
9798
- `TLDR_CACHE_MAX_AGE` (default is `168` hours, which is equivalent to a week): maximum age of the cache in hours to be considered as valid when `TLDR_CACHE_ENABLED` is set to `1`.
9899

99100
#### Cache location
100101

101102
In order of precedence:
103+
102104
- `$XDG_CACHE_HOME/tldr`
103105
- `$HOME/.cache/tldr`
104106
- `~/.cache/tldr`
@@ -130,7 +132,7 @@ an autocomplete for `tldr` for `fish`.
130132

131133
For networks that sit behind a proxy, it may be necessary to disable SSL verification for the client to function. Setting the following:
132134

133-
- `TLDR_ALLOW_INSECURE=1`
135+
- `TLDR_ALLOW_INSECURE=1`
134136

135137
will disable SSL certificate inspection. This __should be avoided__ unless absolutely necessary.
136138

docs/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
# -- Project information -----------------------------------------------------
1818

1919
project = 'tldr'
20-
copyright = '2014, Felix Yan'
21-
author = 'Felix Yan'
20+
copyright = '2014, Felix Yan and 2014-present, tldr-pages contributors'
21+
author = 'Felix Yan and tldr-pages contributors'
2222
from tldr import __version__ # noqa: E402
2323
release = __version__
2424

docs/man/tldr.1

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
.\" Man page generated from reStructuredText.
2+
.
3+
.
4+
.nr rst2man-indent-level 0
5+
.
6+
.de1 rstReportMargin
7+
\\$1 \\n[an-margin]
8+
level \\n[rst2man-indent-level]
9+
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
10+
-
11+
\\n[rst2man-indent0]
12+
\\n[rst2man-indent1]
13+
\\n[rst2man-indent2]
14+
..
15+
.de1 INDENT
16+
.\" .rstReportMargin pre:
17+
. RS \\$1
18+
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
19+
. nr rst2man-indent-level +1
20+
.\" .rstReportMargin post:
21+
..
22+
.de UNINDENT
23+
. RE
24+
.\" indent \\n[an-margin]
25+
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
26+
.nr rst2man-indent-level -1
27+
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
28+
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
29+
..
30+
.TH "TLDR" "1" "Jun 29, 2024" "" "tldr"
31+
.SH NAME
32+
tldr \- tldr 3.3.0
33+
.sp
34+
Python command line client for tldr
35+
36+
.INDENT 0.0
37+
.INDENT 3.5
38+
.sp
39+
.EX
40+
usage: tldr command [options]
41+
.EE
42+
.UNINDENT
43+
.UNINDENT
44+
.SH POSITIONAL ARGUMENTS
45+
.INDENT 0.0
46+
.TP
47+
.B command
48+
command to lookup
49+
.UNINDENT
50+
.SH NAMED ARGUMENTS
51+
.INDENT 0.0
52+
.TP
53+
.B \-v, \-\-version
54+
show program\(aqs version number and exit
55+
.TP
56+
.B \-\-search
57+
Search for a specific command from a query
58+
.TP
59+
.B \-u, \-\-update, \-\-update_cache
60+
Update the local cache of pages and exit
61+
.sp
62+
Default: False
63+
.TP
64+
.B \-p, \-\-platform
65+
Possible choices: android, freebsd, linux, netbsd, openbsd, osx, sunos, windows, common
66+
.sp
67+
Override the operating system [android, freebsd, linux, netbsd, openbsd, osx, sunos, windows, common]
68+
.TP
69+
.B \-l, \-\-list
70+
List all available commands for operating system
71+
.sp
72+
Default: False
73+
.TP
74+
.B \-s, \-\-source
75+
Override the default page source
76+
.sp
77+
Default: \(dq\X'tty: link https://raw.githubusercontent.com/tldr-pages/tldr/main/pages'\fI\%https://raw.githubusercontent.com/tldr\-pages/tldr/main/pages\fP\X'tty: link'\(dq
78+
.TP
79+
.B \-c, \-\-color
80+
Override color stripping
81+
.TP
82+
.B \-r, \-\-render
83+
Render local markdown files
84+
.sp
85+
Default: False
86+
.TP
87+
.B \-L, \-\-language
88+
Override the default language
89+
.TP
90+
.B \-m, \-\-markdown
91+
Just print the plain page file.
92+
.sp
93+
Default: False
94+
.TP
95+
.B \-\-print\-completion
96+
Possible choices: bash, zsh, tcsh
97+
.sp
98+
print shell completion script
99+
.UNINDENT
100+
.SH AUTHOR
101+
Felix Yan and tldr-pages contributors
102+
.SH COPYRIGHT
103+
2014, Felix Yan and 2014-present, tldr-pages contributors
104+
.\" Generated by docutils manpage writer.
105+
.

images/tldr-dark.png

83.1 KB
Loading

setup.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
setup(
1818
name='tldr',
19-
author='Felix Yan',
20-
author_email='[email protected]',
19+
author='Felix Yan and tldr-pages contributors',
2120
url='https://github.com/tldr-pages/tldr-python-client',
2221
description='command line client for tldr',
2322
long_description=Path(setup_dir, 'README.md').open().read(),
@@ -45,12 +44,16 @@
4544
"Natural Language :: English",
4645
"Operating System :: POSIX :: Linux",
4746
"Operating System :: POSIX :: SunOS/Solaris",
47+
"Operating System :: POSIX :: BSD :: FreeBSD",
48+
"Operating System :: POSIX :: BSD :: NetBSD",
49+
"Operating System :: POSIX :: BSD :: OpenBSD",
4850
"Operating System :: MacOS :: MacOS X",
4951
"Operating System :: Microsoft :: Windows",
5052
"Programming Language :: Python :: 3.8",
5153
"Programming Language :: Python :: 3.9",
5254
"Programming Language :: Python :: 3.10",
5355
"Programming Language :: Python :: 3.11",
56+
"Programming Language :: Python :: 3.12",
5457
"Topic :: Utilities",
5558
"Topic :: System"
5659
]

snap/snapcraft.yaml

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
name: tldr # you probably want to 'snapcraft register <name>'
2-
base: core22 # the base snap is the execution environment for this snap
3-
version: '3.2.0' # just for humans, typically '1.2+git' or '1.3.2'
4-
summary: tldr python client # 79 char long summary
1+
name: tldr
2+
base: core24
3+
version: '3.2.0'
4+
summary: tldr python client
55
description: Python command-line client for tldr pages.
66

7-
grade: stable # must be 'stable' to release into candidate/stable channels
8-
confinement: strict # use 'strict' once you have the right plugs and slots
7+
grade: stable
8+
confinement: strict
99

1010
parts:
1111
tldr:
12-
# See 'snapcraft plugins'
1312
plugin: python
1413
source: https://github.com/tldr-pages/tldr-python-client.git
1514
source-tag: $SNAPCRAFT_PROJECT_VERSION
1615
build-environment:
17-
# WORKAROUND: The python plugin is broken with gnome extension
1816
- PATH: ${CRAFT_PART_INSTALL}/bin:${PATH}
19-
- PYTHONPATH: ${CRAFT_PART_INSTALL}/lib/python3.10/site-packages
17+
- PYTHONPATH: ${CRAFT_PART_INSTALL}/lib/python3.12/site-packages
2018
override-pull: |
2119
craftctl default
2220
sed -i "/data_files=\[('share\/man\/man1', \['docs\/man\/tldr\.1'\])\],/d" setup.py
@@ -37,14 +35,14 @@ parts:
3735
- -bin/Activate.ps1
3836
- -bin/python
3937
- -bin/python3
40-
- -bin/python3.10
38+
- -bin/python3.12
4139
- -lib/*/*/sphinx*
4240
- -lib/*/*/setuptools*
4341
- -lib/*/*/pip*
4442
- -lib/*/*/pkg_resources
4543
- -bin/pip
4644
- -bin/pip3
47-
- -bin/pip3.10
45+
- -bin/pip3.12
4846
- -bin/[a-s, u-z, _]*
4947
- -pyvenv.cfg
5048
- -lib/*/*/[a-b, d-r, u-z, A-B, D-R, U-Z, _]*
@@ -56,8 +54,7 @@ apps:
5654
tldr:
5755
command: bin/tldr
5856
environment:
59-
PYTHONPATH: $SNAP/lib/python3.10/site-packages:$PYTHONPATH
60-
#LD_LIBRARY_PATH: $SNAP/lib/man-db:$SNAP/lib:$SNAP/lib/$CRAFT_ARCH_TRIPLET
57+
PYTHONPATH: $SNAP/lib/python3.12/site-packages:$PYTHONPATH
6158
plugs:
6259
- network
6360
- home

tldr.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import colorama # Required for Windows
1919
import shtab
2020

21-
__version__ = "3.2.0"
22-
__client_specification__ = "1.5"
21+
__version__ = "3.3.0"
22+
__client_specification__ = "2.2"
2323

2424
REQUEST_HEADERS = {'User-Agent': 'tldr-python-client'}
2525
PAGES_SOURCE_LOCATION = os.environ.get(
@@ -433,24 +433,35 @@ def output(page: str, plain: bool = False) -> None:
433433
colored(
434434
line.replace('>', '').replace('<', ''),
435435
*colors_of('description')
436-
)
436+
)
437437
sys.stdout.buffer.write(line.encode('utf-8'))
438438
elif line[0] == '-':
439439
line = '\n' + ' ' * LEADING_SPACES_NUM + \
440440
colored(line, *colors_of('example'))
441441
sys.stdout.buffer.write(line.encode('utf-8'))
442442
elif line[0] == '`':
443-
line = line[1:-1] # need to actually parse ``
443+
line = line[1:-1] # Remove backticks for parsing
444+
445+
# Handle escaped placeholders first
446+
line = line.replace(r'\{\{', '__ESCAPED_OPEN__')
447+
line = line.replace(r'\}\}', '__ESCAPED_CLOSE__')
448+
444449
elements = [' ' * 2 * LEADING_SPACES_NUM]
445450
for item in COMMAND_SPLIT_REGEX.split(line):
446451
item, replaced = PARAM_REGEX.subn(
447-
lambda x: colored(
448-
x.group('param'), *colors_of('parameter')),
452+
lambda x: colored(x.group('param'), *colors_of('parameter')),
449453
item)
450454
if not replaced:
451455
item = colored(item, *colors_of('command'))
452456
elements.append(item)
453-
sys.stdout.buffer.write(''.join(elements).encode('utf-8'))
457+
458+
line = ''.join(elements)
459+
460+
# Restore escaped placeholders
461+
line = line.replace('__ESCAPED_OPEN__', '{{')
462+
line = line.replace('__ESCAPED_CLOSE__', '}}')
463+
464+
sys.stdout.buffer.write(line.encode('utf-8'))
454465
print()
455466
print()
456467

0 commit comments

Comments
 (0)