-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathtldr
executable file
Β·135 lines (115 loc) Β· 3.43 KB
/
tldr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env node
const program = require('commander');
const pkg = require('../package');
const Tldr = require('../lib/tldr');
const config = require('../lib/config');
const Platform = require('../lib/platform');
const { TldrError } = require('../lib/errors');
program
.version(pkg.version, '-v, --version', 'Display version')
.helpOption('-h, --help', 'Show this help message')
.description(pkg.description)
.usage('command [options]')
//
// BASIC OPTIONS
//
.option('-l, --list', 'List all commands for the chosen platform in the cache')
.option('-a, --list-all', 'List all commands in the cache')
.option('-1, --single-column', 'List single command per line (use with options -l or -a)')
.option('-r, --random', 'Show a random command')
.option('-e, --random-example', 'Show a random example')
.option('-f, --render [file]', 'Render a specific markdown [file]')
.option('-m, --markdown', 'Output in markdown format')
.option('-p, --platform [type]', 'Override the current platform [android, linux, osx, sunos, windows]')
.option('--android', 'Override the platform with Android')
.option('--linux', 'Override the platform with Linux')
.option('--osx', 'Override the platform with OSX')
.option('--sunos', 'Override the platform with SunOS')
.option('--windows', 'Override the platform with Windows')
.option('-t, --theme [theme]', 'Color theme (simple, base16, ocean)')
.option('-s, --search [keywords]', 'Search pages using keywords')
//
// CACHE MANAGEMENT
//
.option('-u, --update', 'Update the local cache')
.option('-c, --clear-cache', 'Clear the local cache');
const help = `
Examples:
$ tldr tar
$ tldr du --platform=linux
$ tldr --search "create symbolic link to file"
$ tldr --list
$ tldr --list-all
$ tldr --random
$ tldr --random-example
To control the cache:
$ tldr --update
$ tldr --clear-cache
To render a local file (for testing):
$ tldr --render /path/to/file.md
`;
program.on('--help', () => {
console.log(help);
});
program.parse(process.argv);
if(program.android){
program.platform = 'android';
}
if (program.linux) {
program.platform = 'linux';
}
if (program.osx) {
program.platform = 'osx';
}
if (program.sunos) {
program.platform = 'sunos';
}
if (program.windows) {
program.platform = 'windows';
}
let cfg = config.get();
if (program.platform) {
if (Platform.isSupported(program.platform)) {
cfg.platform = program.platform;
}
}
if (program.theme) {
cfg.theme = program.theme;
}
const tldr = new Tldr(cfg);
let p = null;
if (program.list) {
p = tldr.list(program.singleColumn);
} else if (program.listAll) {
p = tldr.listAll(program.singleColumn);
} else if (program.random) {
p = tldr.random(program);
} else if (program.randomExample) {
p = tldr.randomExample();
} else if (program.clearCache) {
p = tldr.clearCache();
} else if (program.update) {
p = tldr.updateCache()
.then(() => {
return tldr.updateIndex();
});
} else if (program.render) {
p = tldr.render(program.render);
} else if (program.search) {
program.args.unshift(program.search);
p = tldr.search(program.args);
} else if (program.args.length >= 1) {
p = tldr.get(program.args, program);
}
if (p === null) {
program.outputHelp();
process.exitCode = 1;
} else {
p.catch((err) => {
let output = TldrError.isTldrError(err)
? err.message
: err.stack;
console.error(output);
process.exitCode = err.code || 1;
});
}