-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix print_usage and man page mistakes #103
Conversation
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]
Just for context, I checked what the client specifications had on this just to make sure we're changing the correct thing. Indeed, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look good to me. Maybe @MasterOdin or @Leandros can take a look.
It appears that using %-30s for padding is unnecessary in this context, as %s alone seems to work perfectly without any issues.
Hopefully this will be the last commit. 🙂 |
If I have time, I can rewrite the arguments so that |
…ded print usage instead.
Not sure what to do with the current usage string. Maybe it should be: tldr [OPTION] PAGE or tldr [ --verbose] [-c|-u] [OPTION]... PAGE But the problem is it doesn't cover options like |
Reverting to the old usage but using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a quick comment or two about behaviour when writing the help. If you do e.g. ls --help
, it exits with code 0. This seems to be a well established pattern, so I'd recommend we do the same here in the Node client.
print_version(argv[0]); | ||
return EXIT_SUCCESS; | ||
print_usage(argv[0]); | ||
return EXIT_FAILURE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this exits with code e.g. 1
instead of 0
when printing help? Other commands e.g. ls
, tar
, etc exit with code 0
when printing help, so we should do the same.
Unless I misunderstood this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our client specification v1.4 suggests to use a non-zero error code for finding pages but doesn't cover the usage part. (tldr-pages/tldr#4246)
Feel free to update the exit code in this branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Specifically, a client MUST exit with a non-zero exit code if the page could not be found anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this exits with code e.g.
1
instead of0
when printing help? Other commands e.g.ls
,tar
, etc exit with code0
when printing help, so we should do the same.
Unless I misunderstood this?
This exits with 1
on a getopt error.
For example:
tldr -a
, which is an unknown argument, exits with1
and displays a getopt error.tldr -v
exits with0
and displays the version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can even test this by running these commands:
$ tldr -a 2> /dev/null; echo $?
1
$ tldr -v > /dev/null; echo $?
0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay. So can you confirm that when you call e.g. tldr --help
it exits with code 0
, @4G3NT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay. So can you confirm that when you call e.g.
tldr --help
it exits with code0
, @4G3NT?
Yes, it exits with code 0
because of this code:
if (help_flag) {
print_usage(argv[0]);
return EXIT_SUCCESS;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool, many thanks!
break; | ||
|
||
case '?': | ||
/* do not set the help flag, only show getopt error */ | ||
/* help_flag = 1; */ | ||
return EXIT_FAILURE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See below comment about exiting with code 0
instead of 1
being preferable when printing help.
And now when you invoke $ tldr -r
./tldr: option requires an argument -- 'r' instead of the last code: $ tldr -r
tldr: option '-render' requires an argument |
Not sure who is generally responsible for the c client but this seems ready to merge for me. |
Usage string is off and this PR fixes it.