Skip to content

Commit c4bcfb0

Browse files
author
4G3NT
authored
Implement short flags and remove --linux, --osx, --sunos (#111)
* Fix argument phrasing * Remove --linux, --osx, and --sunos and update man page * Better consistency with man page * Update README.md
1 parent d0c473f commit c4bcfb0

File tree

3 files changed

+57
-62
lines changed

3 files changed

+57
-62
lines changed

README.md

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A command line client for tldr, written in plain ISO C90.
88

99
On OS X, the client can be installed through [Homebrew](http://brew.sh/).
1010

11-
```shell
11+
```sh
1212
# To install the latest development version
1313
brew install tldr --HEAD
1414

@@ -18,13 +18,13 @@ brew install tldr
1818

1919
On Arch Linux, the client can be installed through [the AUR](https://aur.archlinux.org/packages/tldr-git) using an AUR helper such as yay.
2020

21-
```shell
21+
```sh
2222
yay -S tldr-git
2323
```
2424

2525
To build the latest version from the source:
2626

27-
```shell
27+
```sh
2828
git clone https://github.com/tldr-pages/tldr-c-client.git
2929
cd tldr-c-client
3030

@@ -35,7 +35,7 @@ sudo make install # install tldr
3535

3636
To remove the version installed from the source:
3737

38-
```shell
38+
```sh
3939
sudo make uninstall
4040
```
4141

@@ -60,7 +60,7 @@ in the root directory has all you need for building the project.
6060

6161
Just call `make` and `tldr` will build itself.
6262

63-
```shell
63+
```sh
6464
make
6565
```
6666

@@ -79,29 +79,26 @@ to access the directory (like your home directory), and source it in your `.bash
7979

8080
Example for zsh:
8181

82-
```shell
82+
```sh
8383
mv autocomplete/complete.zsh ~/.tldr.complete
8484
echo "source ~/.tldr.complete" >> ~/.zshrc
8585
```
8686

8787
## Usage
8888

89-
```shell
90-
usage: tldr [-v] [OPTION]... SEARCH
89+
```sh
90+
usage: tldr [OPTION]... PAGE
9191

9292
available commands:
93-
-v print verbose output
94-
--version print version and exit
95-
-h, --help print this help and exit
96-
-u, --update update local database
97-
-c, --clear-cache clear local database
98-
-l, --list list all entries in the local database
93+
-h, --help print this help and exit
94+
-C, --color force color display
9995
-p, --platform=PLATFORM select platform, supported are linux / osx / sunos / windows / common
100-
--linux show command page for Linux
101-
--osx show command page for OSX
102-
--sunos show command page for SunOS
103-
-r, --render=PATH render a local page for testing purposes
104-
-C, --color force color display
96+
-r, --render=PATH render a local page for testing purposes
97+
-u, --update update local database
98+
-v, --version print version and exit
99+
-c, --clear-cache clear local database
100+
-V, --verbose display verbose output (when used with --clear-cache or --update)
101+
-l, --list list all entries in the local database
105102
```
106103
107104
## Configuration

man/tldr.1

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
.\" Manpage for tldr.
22
.\" Contact [email protected] to correct errors or typos.
3-
.mso www.tmac
43
.TH TLDR 1
54
.SH NAME
65
tldr \- A collection of simplified and community-driven man pages.
76
.SH SYNOPSIS
87
.B tldr
9-
[\fB\-C\fR] [\fB\-v\fR] [\fB\-\-clear-cache\fR] [\fB\-\-update\fR] [\fB\-\-list\fR] [\fB\-p\fR \fIPLATFORM\fR]... [\fB\-r\fR \fIPATH\fR] \fIPAGE\fR
8+
[\fB\-C\fR] [\fB\-v\fR] [\fB\-c\fR] [\fB\-u\fR] [\fB\-l\fR] [\fB\-p\fR \fIPLATFORM\fR]... [\fB\-r\fR \fIPATH\fR] \fIPAGE\fR
109
.SH DESCRIPTION
1110
tldr is a collection of simplified and community-driven man pages for commonly used command-line tools.
1211
.SH OPTIONS
1312
.TP
13+
.BR \-h ", " \-\-help
14+
Print help to standard output and exit.
15+
.TP
1416
.BR \-C ", " \-\-color
1517
Force color display.
1618
.TP
@@ -26,23 +28,14 @@ Select platform, supported platforms are \fIlinux\fR / \fIosx\fR / \fIsunos\fR /
2628
.BR \-r ", " \-\-render=\fIPATH\fR
2729
Render a local page for testing purposes.
2830
.TP
29-
.BR \-\-clear-cache
31+
.BR \-c ", " \-\-clear-cache
3032
Remove the local database and exit.
3133
.TP
32-
.BR \-\-linux
33-
Show command page for Linux.
34-
.TP
35-
.BR \-\-list
34+
.BR \-l ", " \-\-list
3635
List all entries in the local database.
3736
.TP
38-
.BR \-\-osx
39-
Show command page for OSX.
40-
.TP
41-
.BR \-\-sunos
42-
Show command page for SunOS.
43-
.TP
44-
.BR \-\-verbose
45-
Print verbose output (when used with \fB\-\-clear-cache\fR or \fB\-\-update\fR).
37+
.BR \-V ", " \-\-verbose
38+
Print verbose output (when used with \fB\-c\fR or \fB\-u\fR).
4639
.SH EXIT STATUS
4740
0 on success, any other positive value otherwise.
4841
.SH SEE ALSO

src/tldr.c

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ static struct option long_options[] = {
4343
{"update", no_argument, &update_flag, 1},
4444
{"clear-cache", no_argument, &clear_flag, 1},
4545
{"platform", required_argument, 0, 'p'},
46-
{"linux", no_argument, 0, 'p'},
47-
{"osx", no_argument, 0, 'p'},
48-
{"sunos", no_argument, 0, 'p'},
49-
{"list", no_argument, &list_flag, 'l'},
46+
{"list", no_argument, &list_flag, 1},
5047
{"render", required_argument, 0, 'r'},
51-
{"color", no_argument, &color_flag, 'C'},
52-
{0, 0, 0, 0}};
48+
{"color", no_argument, &color_flag, 1},
49+
{ 0 }
50+
};
5351

5452
int main(int argc, char **argv) {
5553
int c;
@@ -70,7 +68,7 @@ int main(int argc, char **argv) {
7068

7169
while (1) {
7270
option_index = 0;
73-
c = getopt_long_only(argc, argv, "vp:r:C", long_options, &option_index);
71+
c = getopt_long(argc, argv, "hvVucp:lr:C", long_options, &option_index);
7472

7573
/* reached the end, bail out */
7674
if (c == -1) {
@@ -91,20 +89,10 @@ int main(int argc, char **argv) {
9189
return EXIT_FAILURE;
9290
break;
9391

94-
case 'p': {
95-
const char *platform_name = long_options[option_index].name;
96-
if (strcmp(platform_name, "platform") == 0) {
97-
size_t len = strlen(optarg);
98-
if (len > STRBUFSIZ)
99-
exit(EXIT_FAILURE);
100-
101-
memcpy(pbuf, optarg, len);
102-
pbuf[len] = '\0';
103-
} else {
104-
memcpy(pbuf, platform_name, strlen(platform_name));
105-
}
92+
case 'p':
93+
memcpy(pbuf, optarg, strlen(optarg));
10694
platform_flag = 1;
107-
} break;
95+
break;
10896

10997
case 'r': {
11098
size_t len = strlen(optarg);
@@ -120,6 +108,26 @@ int main(int argc, char **argv) {
120108
color_flag = 1;
121109
break;
122110

111+
case 'h':
112+
help_flag = 1;
113+
break;
114+
115+
case 'l':
116+
list_flag = 1;
117+
break;
118+
119+
case 'V':
120+
verbose_flag = 1;
121+
break;
122+
123+
case 'u':
124+
update_flag = 1;
125+
break;
126+
127+
case 'c':
128+
clear_flag = 1;
129+
break;
130+
123131
default:
124132
abort();
125133
}
@@ -216,24 +224,21 @@ void print_version(char const *arg) {
216224
}
217225

218226
void print_usage(char const *arg){
219-
char const *out = "usage: %s [--verbose] [OPTION]... [PAGE]\n\n";
227+
char const *out = "usage: %s [OPTION]... PAGE\n\n";
220228

221229
/* *INDENT-OFF* */
222230
fprintf(stdout, out, arg);
223231
fprintf(stdout, "available commands:\n");
224-
fprintf(stdout, " %-23s %s\n", "-C, --color", "force color display");
225232
fprintf(stdout, " %-23s %s\n", "-h, --help", "print this help and exit");
233+
fprintf(stdout, " %-23s %s\n", "-C, --color", "force color display");
226234
fprintf(stdout, " %-23s %s\n", "-p, --platform=PLATFORM",
227235
"select platform, supported are linux / osx / sunos / windows / common");
228236
fprintf(stdout, " %-23s %s\n", "-r, --render=PATH",
229237
"render a local page for testing purposes");
230238
fprintf(stdout, " %-23s %s\n", "-u, --update", "update local database");
231239
fprintf(stdout, " %-23s %s\n", "-v, --version", "print version and exit");
232-
fprintf(stdout, " %-23s %s\n", "--clear-cache", "clear local database");
233-
fprintf(stdout, " %-23s %s\n", "--verbose", "display verbose output (when used with --clear-cache or --update)");
234-
fprintf(stdout, " %-23s %s\n", "--list", "list all entries in the local database");
235-
fprintf(stdout, " %-23s %s\n", "--linux", "show command page for Linux");
236-
fprintf(stdout, " %-23s %s\n", "--osx", "show command page for OSX");
237-
fprintf(stdout, " %-23s %s\n", "--sunos", "show command page for SunOS");
240+
fprintf(stdout, " %-23s %s\n", "-c, --clear-cache", "clear local database");
241+
fprintf(stdout, " %-23s %s\n", "-V, --verbose", "display verbose output (when used with -c or -u)");
242+
fprintf(stdout, " %-23s %s\n", "-l, --list", "list all entries in the local database");
238243
/* *INDENT-ON* */
239244
}

0 commit comments

Comments
 (0)