Skip to content

Commit

Permalink
Fix print_usage and man page mistakes (#103)
Browse files Browse the repository at this point in the history
* Fix print_usage mistakes

Seems like someone confused tldr-c-client with another client because -v prints out version and you can't even search for a string instead you have to provide a [PAGE]

* Fix the manual page as well

* Remove redundancy and fix man page URLs

* Add a period ad the end of the urls

* Fix man page mistakes and update usage

* Fix capitalization

* Reorder options in a more logical manner

* Remove unused variable in deps.sh

* remove non-existing options and add other options to man page

* Remove obsolete padding code

It appears that using %-30s for padding is unnecessary in this context, as %s alone seems to work perfectly without any issues.

* Replace "[PAGE]" with "PAGE" to comply with usual conventions

* Prevent -v from printing version if no additional arguments are provided print usage instead.

* Use literal URLs in the man page to increase compatiability between mandoc and man-db

* Comply with padding of 80 colums

* Client specification compliant does the opposite of commit 32c7172

* Fix exit codes and more descriptive usage info for --verbose

* More valid --verbose description

* Revert to old usage, but use the long option instead

* Revert to old usage, but use the long option instead

man

* Revert accidental changes

* tldr.1: update manpage

* tldr.c: fix EOL

* Properly align print_usage

* Fix whitespace and argument phrasing

---------

Co-authored-by: K.B.Dharun Krishna <[email protected]>
  • Loading branch information
4G3NT and kbdharun authored Nov 23, 2023
1 parent c741caf commit d0c473f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 44 deletions.
1 change: 0 additions & 1 deletion deps.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/sh

UNAME=$(uname -s)
ARCH=$(uname -m)

if [ "$UNAME" = "Darwin" ]; then
HAS_BREW=$(command -v brew > /dev/null 2>&1 && echo 1 || echo 0)
Expand Down
53 changes: 31 additions & 22 deletions man/tldr.1
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,52 @@
tldr \- A collection of simplified and community-driven man pages.
.SH SYNOPSIS
.B tldr
[\fB\-v\fR]
[\fIOPTION\fR]... \fISEARCH\fR
[\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
.SH DESCRIPTION
tldr is a collection of simplified and community-driven man pages, for commonly
used commandline tools.
tldr is a collection of simplified and community-driven man pages for commonly used command-line tools.
.SH OPTIONS
.TP
.BR \-v
verbose output
.BR \-C ", " \-\-color
Force color display.
.TP
.BR \-\-version
output version information and exit
.TP
.BR \-h ", " \-\-help
display help and exit
.BR \-v ", " \-\-version
Output version information and exit.
.TP
.BR \-u ", " \-\-update
update local database and exit
.TP
.BR \-c ", " \-\-clear-cache
remove local database and exit
Update the local database and exit.
.TP
.BR \-p ", " \-\-platform=\fIPLATFORM\fR
select platform, supported are \fIlinux\fR / \fIosx\fR / \fIsunos\fR / \fIwindows\fR / \fIcommon\fR
Select platform, supported platforms are \fIlinux\fR / \fIosx\fR / \fIsunos\fR / \fIwindows\fR / \fIcommon\fR.
.TP
.BR \-r ", " \-\-render=\fIPATH\fR
render a local page for testing purposes
Render a local page for testing purposes.
.TP
.BR \-\-clear-cache
Remove the local database and exit.
.TP
.BR \-\-linux
Show command page for Linux.
.TP
.BR \-\-list
List all entries in the local database.
.TP
.BR \-\-osx
Show command page for OSX.
.TP
.BR \-\-sunos
Show command page for SunOS.
.TP
.BR \-\-verbose
Print verbose output (when used with \fB\-\-clear-cache\fR or \fB\-\-update\fR).
.SH EXIT STATUS
0 on success, any other positive value otherwise
0 on success, any other positive value otherwise.
.SH SEE ALSO
The source is available at:
.URL "https://github.com/tldr-pages/tldr-cpp-client" "" ""
<https://github.com/tldr-pages/tldr-c-client>.
.SH REPORTING BUGS
Report bugs through the Github repository:
.URL "https://github.com/tldr-pages/tldr-cpp-client" "" "."
Report bugs through the GitHub repository:
<https://github.com/tldr-pages/tldr-c-client>.
.SH COPYRIGHT
The MIT License (MIT)

Copyright (c) 2016 Arvid Gerstmann.

4 changes: 2 additions & 2 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ parse_tldrpage(char const *input, int color_enabled)

case '-':
start = i;
if (color_enabled)
if (color_enabled)
fprintf(stdout, "%s", ANSI_COLOR_COMMENT_FG);
continue;

case '`':
start = i;
if (color_enabled)
if (color_enabled)
fprintf(stdout, "%s", ANSI_COLOR_CODE_FG);
fprintf(stdout, " ");
continue;
Expand Down
43 changes: 24 additions & 19 deletions src/tldr.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int main(int argc, char **argv) {

while (1) {
option_index = 0;
c = getopt_long_only(argc, argv, "v", long_options, &option_index);
c = getopt_long_only(argc, argv, "vp:r:C", long_options, &option_index);

/* reached the end, bail out */
if (c == -1) {
Expand All @@ -82,12 +82,13 @@ int main(int argc, char **argv) {
break;

case 'v':
verbose_flag = 1;
version_flag = 1;
break;

case '?':
/* do not set the help flag, only show getopt error */
/* help_flag = 1; */
return EXIT_FAILURE;
break;

case 'p': {
Expand Down Expand Up @@ -130,10 +131,14 @@ int main(int argc, char **argv) {

/* show help, if the platform was supplied, but no further argument */
missing_arg = (platform_flag && !list_flag && (optind == argc));
if (help_flag || missing_arg) {
if (help_flag) {
print_usage(argv[0]);
return EXIT_SUCCESS;
}
if (missing_arg) {
print_usage(argv[0]);
return EXIT_FAILURE;
}
if (version_flag) {
print_version(argv[0]);
return EXIT_SUCCESS;
Expand All @@ -149,8 +154,8 @@ int main(int argc, char **argv) {
return EXIT_SUCCESS;
}
if (verbose_flag && optind >= argc) {
print_version(argv[0]);
return EXIT_SUCCESS;
print_usage(argv[0]);
return EXIT_FAILURE;
}
if (list_flag) {
if (!has_localdb())
Expand Down Expand Up @@ -210,25 +215,25 @@ void print_version(char const *arg) {
/* *INDENT-ON* */
}

void print_usage(char const *arg) {
char const *out = "usage: %s [-v] [OPTION]... SEARCH\n\n";
void print_usage(char const *arg){
char const *out = "usage: %s [--verbose] [OPTION]... [PAGE]\n\n";

/* *INDENT-OFF* */
fprintf(stdout, out, arg);
fprintf(stdout, "available commands:\n");
fprintf(stdout, " %-20s %-30s\n", "-v", "print verbose output");
fprintf(stdout, " %-20s %-30s\n", "--version", "print version and exit");
fprintf(stdout, " %-20s %-30s\n", "-h, --help", "print this help and exit");
fprintf(stdout, " %-20s %-30s\n", "-u, --update", "update local database");
fprintf(stdout, " %-20s %-30s\n", "-c, --clear-cache", "clear local database");
fprintf(stdout, " %-20s %-30s\n", "-l, --list", "list all entries in the local database");
fprintf(stdout, " %-20s %-30s\n", "-p, --platform=PLATFORM",
fprintf(stdout, " %-23s %s\n", "-C, --color", "force color display");
fprintf(stdout, " %-23s %s\n", "-h, --help", "print this help and exit");
fprintf(stdout, " %-23s %s\n", "-p, --platform=PLATFORM",
"select platform, supported are linux / osx / sunos / windows / common");
fprintf(stdout, " %-20s %-30s\n", "--linux", "show command page for Linux");
fprintf(stdout, " %-20s %-30s\n", "--osx", "show command page for OSX");
fprintf(stdout, " %-20s %-30s\n", "--sunos", "show command page for SunOS");
fprintf(stdout, " %-20s %-30s\n", "-r, --render=PATH",
fprintf(stdout, " %-23s %s\n", "-r, --render=PATH",
"render a local page for testing purposes");
fprintf(stdout, " %-20s %-30s\n", "-C, --color", "force color display");
fprintf(stdout, " %-23s %s\n", "-u, --update", "update local database");
fprintf(stdout, " %-23s %s\n", "-v, --version", "print version and exit");
fprintf(stdout, " %-23s %s\n", "--clear-cache", "clear local database");
fprintf(stdout, " %-23s %s\n", "--verbose", "display verbose output (when used with --clear-cache or --update)");
fprintf(stdout, " %-23s %s\n", "--list", "list all entries in the local database");
fprintf(stdout, " %-23s %s\n", "--linux", "show command page for Linux");
fprintf(stdout, " %-23s %s\n", "--osx", "show command page for OSX");
fprintf(stdout, " %-23s %s\n", "--sunos", "show command page for SunOS");
/* *INDENT-ON* */
}

0 comments on commit d0c473f

Please sign in to comment.