Skip to content

Commit 98de9cb

Browse files
kbdharunMasterOdin
andauthoredNov 14, 2023
feat (3.4.0): add platform option, Android and BSD platforms (#421)
* feat: add platform option, Android platform Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * feat/test: update code, add alias for old options Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * feat: rename platform lib to platforms Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * Update bin/tldr Co-authored-by: Matthew Peveler <matt.peveler@gmail.com> * feat: add support for OpenBSD and update code Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * fix: add back updated platform options Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * cleanup: update files Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * Update bin/completion/bash/tldr Co-authored-by: Matthew Peveler <matt.peveler@gmail.com> * feat: add support for FreeBSD and NetBSD Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * cleanup: rearrange options, prepare for 3.4.0 Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * README: minor fixes Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * Fix URL-encoded email highlighting Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * cleanup: add release CI, drop Node 14 support Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * cleanup: remove not working alias option Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> --------- Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> Co-authored-by: Matthew Peveler <matt.peveler@gmail.com>
1 parent 97bd716 commit 98de9cb

19 files changed

+261
-159
lines changed
 

‎.github/workflows/publish.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This workflow automatically publishes the package to NPM when a new release is created.
2+
# Before, creating a new release, make sure to update the package version in package.json
3+
# and add a Granular Access Token (with read and write packages scope)
4+
# to the repository secrets with the name NPM_TOKEN.
5+
# Once, the release has been published remove it from the repository secrets.
6+
7+
name: Publish Package to NPM
8+
on:
9+
release:
10+
types: [published]
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
# Setup .npmrc file to publish to npm
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: '20.x'
20+
registry-url: 'https://registry.npmjs.org'
21+
- run: npm ci
22+
- run: npm publish
23+
env:
24+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

‎.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
${{ matrix.os }}-npm-
3535
3636
- name: Use Node.js ${{ matrix.node-version }}
37-
uses: actions/setup-node@v3
37+
uses: actions/setup-node@v4
3838
with:
3939
node-version: ${{ matrix.node-version }}
4040

‎README.md

+23-20
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,19 @@ npm install -g tldr
2121
To see tldr pages:
2222

2323
- `tldr <command>` show examples for this command
24-
- `tldr <command> --os=<platform>` show command page for the given platform (`linux`, `osx`, `sunos`, `windows`)
25-
- `tldr --search "<query>"` search all pages for the query
24+
- `tldr <command> --platform=<osx, darwin, macos, freebsd, linux, netbsd, openbsd, sunos, android, windows, win32>` show command page for the given platform
25+
- `tldr --android <command>` show command page for Android
26+
- `tldr --darwin <command>` show command page for darwin (macOS)
27+
- `tldr --freebsd <command>` show command page for FreeBSD
2628
- `tldr --linux <command>` show command page for Linux
27-
- `tldr --osx <command>` show command page for OSX
29+
- `tldr --macos <command>` show command page for macOS
30+
- `tldr --netbsd <command>` show command page for NetBSD
31+
- `tldr --openbsd <command>` show command page for OpenBSD
32+
- `tldr --osx <command>` show command page for osx (macOS)
2833
- `tldr --sunos <command>` show command page for SunOS
34+
- `tldr --win32 <command>` show command page for win32 (Windows)
2935
- `tldr --windows <command>` show command page for Windows
36+
- `tldr --search "<query>"` search all pages for the query
3037
- `tldr --list` show all pages for current platform
3138
- `tldr --list-all` show all available pages
3239
- `tldr --random` show a page at random
@@ -91,7 +98,7 @@ you can put it in the config file:
9198
The default platform value can be overwritten with command-line option:
9299

93100
```shell
94-
tldr du --os=osx
101+
tldr du --platform=<osx>
95102
```
96103

97104
As a contributor, you can also point to your own fork containing the `tldr.zip` file. The file is just a zipped version of the entire tldr repo:
@@ -122,7 +129,7 @@ It's easiest for
122129
[oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh)
123130
users, so let's start with that.
124131

125-
```
132+
```zsh
126133
mkdir -p $ZSH_CUSTOM/plugins/tldr
127134
ln -s bin/completion/zsh/_tldr $ZSH_CUSTOM/plugins/tldr/_tldr
128135
```
@@ -131,13 +138,13 @@ Then add tldr to your oh-my-zsh plugins,
131138
usually defined in `~/.zshrc`,
132139
resulting in something looking like this:
133140

134-
```
141+
```zsh
135142
plugins=(git tmux tldr)
136143
```
137144

138145
Alternatively, using [zplug](https://github.com/zplug/zplug)
139146

140-
```
147+
```zsh
141148
zplug "tldr-pages/tldr-node-client", use:bin/completion/zsh
142149
```
143150

@@ -147,37 +154,37 @@ Copy or symlink `bin/completion/zsh/_tldr` to
147154
(note the filename).
148155
Then add the containing directory to your fpath:
149156

150-
```
157+
```zsh
151158
fpath=(my/completions $fpath)
152159
```
153160

154161
### Bash
155162

156-
```
163+
```bash
157164
ln -s bin/completion/bash/tldr ~/.tldr-completion.bash
158165
```
159166

160167
Now add the following line to our bashrc file:
161168

162-
```
169+
```bash
163170
source ~/.tldr-completion.bash
164171
```
165172

166173
## FAQ
167174

168-
#### Installation Issues
175+
### Installation Issues
169176

170177
- If you are trying to install as non-root user (`npm install -g tldr`) and get something like:
171178

172-
```
179+
```text
173180
Error: EACCES: permission denied, access '/usr/local/lib/node_modules/tldr'
174181
```
175182

176183
Then most probably your npm's default installation directory has improper permissions. You can resolve it by clicking [here](https://docs.npmjs.com/getting-started/fixing-npm-permissions)
177184

178185
- If you are trying to install as a root user (`sudo npm install -g tldr`) and get something like:
179186

180-
```
187+
```shell
181188
as root ->
182189
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/tldr/node_modules/webworker-threads/.node-gyp"
183190
gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/local/lib/node_modules/tldr/node_modules/webworker-threads/.node-gyp/8.9.1"
@@ -187,14 +194,14 @@ You need to add the option `--unsafe-perm` to your command. This is because when
187194

188195
- If you see an error related to `webworker-threads` like:
189196

190-
```
197+
```text
191198
/usr/local/lib/node_modules/tldr/node_modules/natural/lib/natural/classifiers/classifier.js:32
192199
if (e.code !== 'MODULE_NOT_FOUND') throw e;
193200
```
194201

195202
Most probably you need to reinstall `node-gyp` and `webworker-threads`. Try this -
196203

197-
```
204+
```shell
198205
sudo -H npm uninstall -g tldr
199206
sudo -H npm uninstall -g webworker-threads
200207
npm install -g node-gyp
@@ -236,10 +243,6 @@ for a few rough guidelines.
236243
[npm-url]: https://www.npmjs.com/package/tldr
237244
[npm-image]: https://img.shields.io/npm/v/tldr.svg
238245
[gh-actions-url]: https://github.com/tldr-pages/tldr-node-client/actions?query=workflow%3ATest+branch%3Amaster
239-
[gh-actions-image]: https://img.shields.io/github/actions/workflow/status/tldr-pages/tldr-node-client/test.yml?branch=master
240-
[dep-url]: https://david-dm.org/tldr-pages/tldr-node-client
241-
[dep-image]: https://david-dm.org/tldr-pages/tldr-node-client.svg?theme=shields.io
242-
[dev-dep-url]: https://david-dm.org/tldr-pages/tldr-node-client#info=devDependencies
243-
[dev-dep-image]: https://david-dm.org/tldr-pages/tldr-node-client/dev-status.svg?theme=shields.io
246+
[gh-actions-image]: https://img.shields.io/github/actions/workflow/status/tldr-pages/tldr-node-client/test.yml?branch=main
244247
[matrix-url]: https://matrix.to/#/#tldr-pages:matrix.org
245248
[matrix-image]: https://img.shields.io/matrix/tldr-pages:matrix.org?label=chat+on+matrix

‎bin/completion/bash/tldr

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
BUILTIN_THEMES="single base16 ocean"
44

5-
OS_TYPES="linux osx sunos windows"
5+
PLATFORM_TYPES="android freebsd linux netbsd openbsd osx sunos windows"
66

77
OPTIONS='-v
88
--version
@@ -20,10 +20,17 @@ OPTIONS='-v
2020
--render
2121
-m
2222
--markdown
23-
-o
23+
-p
24+
--android
25+
--darwin
26+
--freebsd
2427
--linux
28+
--macos
29+
--netbsd
30+
--openbsd
2531
--osx
2632
--sunos
33+
--win32
2734
--windows
2835
-t
2936
--theme
@@ -56,8 +63,8 @@ function _tldr_autocomplete {
5663
COMPREPLY=(`compgen -f $cur`)
5764
;;
5865

59-
-o|--os)
60-
COMPREPLY=(`compgen -W "$OS_TYPES" $cur`)
66+
-p|--platform)
67+
COMPREPLY=(`compgen -W "$PLATFORM_TYPES" $cur`)
6168
;;
6269

6370
-t|--theme)

‎bin/completion/zsh/_tldr

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#compdef tldr
22

3-
local -a pages oses
3+
local -a pages platforms
44
pages=$(tldr -a1)
5-
oses='( linux osx sunos windows )'
5+
platforms='( android freebsd linux netbsd openbsd osx sunos windows )'
66

77
_arguments \
88
'(- *)'{-h,--help}'[show help]' \
@@ -15,11 +15,18 @@ _arguments \
1515
'(- *)'{-e,--random-example}'[show a random example]' \
1616
'(- *)'{-m,--markdown}'[show the original markdown format page]' \
1717
'(-f --render)'{-f,--render}'[render a specific markdown file]:markdown file:_files -/' \
18-
'(-o --os)'{-o,--os}"[override operating system]:os:${oses}" \
18+
'(-p --platform)'{-p,--platform}"[override platform]:platform:(${(j:|:)platforms})" \
19+
'(- *)'{-u,--update}'[update local cache]' \
20+
'--android[override operating system with Android]' \
21+
'--darwin[override operating system with macOS]' \
22+
'--freebsd[override operating system with FreeBSD]' \
1923
'--linux[override operating system with Linux]' \
20-
'--osx[override operating system with OSX]' \
24+
'--macos[override operating system with macOS]' \
25+
'--netbsd[override operating system with NetBSD]' \
26+
'--openbsd[override operating system with OpenBSD]' \
27+
'--osx[override operating system with macOS]' \
2128
'--sunos[override operating system with SunOS]' \
29+
'--win32[override operating system with Windows]' \
2230
'--windows[override operating system with Windows]' \
23-
'(- *)'{-u,--update}'[update local cache]' \
2431
'(- *)'{-c,--clear-cache}'[clear local cache]' \
2532
"*:page:(${(b)pages})" && return 0

‎bin/tldr

+17-25
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ const program = require('commander');
44
const pkg = require('../package');
55
const Tldr = require('../lib/tldr');
66
const config = require('../lib/config');
7-
const platform = require('../lib/platform');
7+
const platforms = require('../lib/platforms');
88
const { TldrError } = require('../lib/errors');
99

10+
pkg.version = `v${pkg.version}\nClient Specification: 2.0`;
11+
1012
program
1113
.version(pkg.version, '-v, --version', 'Display version')
1214
.helpOption('-h, --help', 'Show this help message')
@@ -22,11 +24,13 @@ program
2224
.option('-e, --random-example', 'Show a random example')
2325
.option('-f, --render [file]', 'Render a specific markdown [file]')
2426
.option('-m, --markdown', 'Output in markdown format')
25-
.option('-o, --os [type]', 'Override the operating system [linux, osx, sunos, windows]')
26-
.option('--linux', 'Override the operating system with Linux')
27-
.option('--osx', 'Override the operating system with OSX')
28-
.option('--sunos', 'Override the operating system with SunOS')
29-
.option('--windows', 'Override the operating system with Windows')
27+
.option('-p, --platform [type]', `Override the current platform [${platforms.supportedPlatforms.join(', ')}]`);
28+
29+
for (const platform of platforms.supportedPlatforms) {
30+
program.option(`--${platform}`, `Override the platform with ${platform}`);
31+
}
32+
33+
program
3034
.option('-t, --theme [theme]', 'Color theme (simple, base16, ocean)')
3135
.option('-s, --search [keywords]', 'Search pages using keywords')
3236
//
@@ -39,7 +43,7 @@ const help = `
3943
Examples:
4044
4145
$ tldr tar
42-
$ tldr du --os=linux
46+
$ tldr du --platform=linux
4347
$ tldr --search "create symbolic link to file"
4448
$ tldr --list
4549
$ tldr --list-all
@@ -62,27 +66,15 @@ program.on('--help', () => {
6266

6367
program.parse(process.argv);
6468

65-
if (program.linux) {
66-
program.os = 'linux';
67-
}
68-
69-
if (program.osx) {
70-
program.os = 'osx';
71-
}
72-
73-
if (program.sunos) {
74-
program.os = 'sunos';
75-
}
76-
77-
if (program.windows) {
78-
program.os = 'windows';
69+
for (const platform of platforms.supportedPlatforms) {
70+
if (program[platform]) {
71+
program.platform = platform;
72+
}
7973
}
8074

8175
let cfg = config.get();
82-
if (program.os) {
83-
if (platform.isSupported(program.os)) {
84-
cfg.platform = program.os;
85-
}
76+
if (program.platform && platforms.isSupported(program.platform)) {
77+
cfg.platform = program.platform;
8678
}
8779

8880
if (program.theme) {

‎lib/cache.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ const fs = require('fs-extra');
44
const os = require('os');
55
const path = require('path');
66
const remote = require('./remote');
7-
const platform = require('./platform');
7+
const platforms = require('./platforms');
88
const index = require('./index');
99
const utils = require('./utils');
1010

1111
class Cache {
1212
constructor(config) {
13-
// TODO: replace this with a private field when it reaches enough maturity
14-
// https://github.com/tc39/proposal-class-fields#private-fields
1513
this.config = config;
1614
this.cacheFolder = path.join(config.cache, 'cache');
1715
}
@@ -21,7 +19,7 @@ class Cache {
2119
}
2220

2321
getPage(page) {
24-
let preferredPlatform = platform.getPreferredPlatformFolder(this.config);
22+
let preferredPlatform = platforms.getPreferredPlatformFolder(this.config);
2523
const preferredLanguage = process.env.LANG || 'en';
2624
return index.findPage(page, preferredPlatform, preferredLanguage)
2725
.then((folder) => {

‎lib/config.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const fs = require('fs');
55
const path = require('path');
66
const utils = require('./utils');
77
const osHomedir = require('os').homedir;
8+
const platforms = require('./platforms');
89

910
exports.get = () => {
1011
const DEFAULT = path.join(__dirname, '..', 'config.json');
@@ -55,10 +56,9 @@ exports.get = () => {
5556
return merged;
5657
};
5758

58-
function validatePlatform(os) {
59-
let platform = require('./platform');
60-
if (os && !platform.isSupported(os)) {
61-
return 'Unsupported platform : ' + os;
59+
function validatePlatform(platform) {
60+
if (platform && !platforms.isSupported(platform)) {
61+
return 'Unsupported platform : ' + platform;
6262
}
6363
return null;
6464
}
@@ -118,4 +118,4 @@ function validateThemeItem(field, key) {
118118
return null;
119119
}
120120
return errMsg.join('\n');
121-
}
121+
}

0 commit comments

Comments
 (0)