-
Notifications
You must be signed in to change notification settings - Fork 478
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
uftrace: Add sub-command specific help #1946
Conversation
2f1fac3
to
0a198f0
Compare
First, thanks for posting the commit that fixes #1316. However, for a better commit message, you should follow the 50/72 rule[1], and the body of this commit message doesn't seem to do that. Could you please make this change? And this is my personal opinion based on existing cefd9be, 0ac2cef PRs, but I think the [1] https://www.gitkraken.com/learn/git/best-practices/git-commit-message#git-commit-message-structure |
Thanks for the PR @ParkSeungHyeok and thanks for the review @gichoel. |
0a198f0
to
42477f7
Compare
uftrace.c
Outdated
pr_out(uftrace_usage); | ||
pr_out(uftrace_help); | ||
wait_for_pager(); | ||
if (!(opts.mode)) { |
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.
Hello @ParkSeungHyeok, We can follow the convention simply with !opts.mode
.
42477f7
to
f738867
Compare
thank you for review @gichoel , @honggyukim, @yskelg |
Thank you @ParkSeungHyeok, LGTM |
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.
Thanks for the update. Your name is currently written as ParkSeungHyeok
, but it is better to be changed because I don't think you write your name without having spaces.
Maybe one of the following is better.
Park SeungHyeok
SeungHyeok Park
Seunghyeok Park
You can choose which one to use. Please make sure you update your name in both in the commit author name and Signed-off-by
.
f738867
to
f0572f5
Compare
@honggyukim i agree your recommendation. it looks better. |
Thanks. One more request is to change the error message when
Maybe we better handle it just like
|
@honggyukim Okay i agree then how about below code? +static void show_man_page(char *sub_command)
+{
+ char * page = xmalloc(sizeof("uftrace-"));
+ strcpy(page,"uftrace-");
+ page = strjoin(page,sub_command,"");
+ execlp("man", "man", page, (char *)NULL);
+}
int main(int argc, char *argv[])
{
...
case -3:
+ if (opts.mode) {
+ show_man_page(argv[1]);
+ abort();
+ }
if (opts.use_pager)
start_pager(setup_pager());
pr_out(uftrace_usage);
pr_out(uftrace_help);
wait_for_pager();
ret = 0;
goto cleanup;
}
...
} i not sure if it is okay to make new function int main(int argc, char *argv[])
{
...
+ char * page = xmalloc(sizeof("uftrace-"));
...
case -3:
+ if (opts.mode) {
+ strcpy(page,"uftrace-");
+ page = strjoin(page,argv[1],"");
+ execlp("man", "man", page, (char *)NULL);
+ abort();
+ }
if (opts.use_pager)
start_pager(setup_pager());
pr_out(uftrace_usage);
pr_out(uftrace_help);
wait_for_pager();
ret = 0;
goto cleanup;
}
...
} |
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.
Thanks for the contribution!
uftrace.c
Outdated
@@ -1428,6 +1428,10 @@ int main(int argc, char *argv[]) | |||
ret = 0; | |||
goto cleanup; | |||
case -3: | |||
if (opts.mode) { | |||
execlp("man", "man", "uftrace", argv[1], (char *)NULL); | |||
abort(); |
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 don't think we need abort()
here and maybe it's better to call exit(1)
instead. But we used to show the full message for the --help
option, so it'd be natural to fall back to the old behavior if no manual pages are available.
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.
abort()
here is to show this is unreachable. It doesn't hit the abort()
even if No manual entry for ...
error message is shown.
But it may be reachable if man
command itself is not found in the system, which is very unlikely. Maybe the following is better to cover such case as well.
case -3:
if (opts.mode) {
execlp("man", "man", "uftrace", argv[1], (char *)NULL);
/* fall through if man command itself is not found */
}
if (opts.use_pager)
start_pager(setup_pager());
pr_out(uftrace_usage);
pr_out(uftrace_help);
wait_for_pager();
ret = 0;
goto cleanup;
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.
But we used to show the full message for the --help option, so it'd be natural to fall back to the old behavior if no manual pages are available.
Once the man
command is executed by execlp
, then there is no way to go back to the fallback routine. If that is really needed, then we should check whether the proper man page can be found before calling execlp
. But I think we don't have to make it too much complicated.
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.
Oh.. ok. But sometimes man
might not be installed. I admit it's a rare condition. :)
Considering all our conversation, we can think about this. static void show_man_page(char *cmd)
{
char *cmdstr = NULL;
if (cmd)
xasprintf(&cmdstr, "uftrace-%s", cmd);
else
cmdstr = xstrdup("uftrace");
execlp("man", "man", cmdstr, (char *)NULL);
/* fall through if man command itself is not found */
free(cmdstr);
}
...
int main(int argc, char *argv[])
{
...
switch (parse_options(argc, argv, &opts)) {
...
case -3:
if (opts.mode)
show_man_page(argv[1]);
if (opts.use_pager)
start_pager(setup_pager());
pr_out(uftrace_usage);
pr_out(uftrace_help);
wait_for_pager();
ret = 0;
goto cleanup;
}
...
} |
f0572f5
to
e263f78
Compare
thank you for review @namhyung @honggyukim but i wonder how to reach below code else
cmdstr = xstrdup("uftrace"); is it for another case later? |
My mistake. |
e263f78
to
328c10a
Compare
You should put
https://github.com/namhyung/uftrace/actions/runs/10432184123/job/28892638730?pr=1946 |
328c10a
to
c25aca6
Compare
Looks good now. The last request is please read other commit message and make it similar. I'm typing in my phone so can't tell you the details but please read other commit messages more to learn the convention. |
thank you for your detailed review @honggyukim but although it is else
cmdstr = xstrdup("uftrace"); i mean... and... |
Thanks for your work and effort as well!
That is the caller dependent point of view. When you write a function, you better handle all the possible cases regardless of the input argument.
I would write the commit message as follows.
|
c25aca6
to
4216d6a
Compare
It's just a nitpick but please begin a sentence in a capital letter unless you have a strong reason for that. You can think the commit message like sending an email to someone. |
This patch adds sub-command specific help by redirecting the help message to their man pages of each command just like git and perf do. The simple usage is as follows. $ uftrace [COMMAND] --help Then you will see the man page of given '[COMMAND]' such as record, replay and so on. Fixed: namhyung#1316 Signed-off-by: Seunghyeok Park <tmdgur1324@naver.com>
4216d6a
to
1848e1a
Compare
thank you @honggyukim |
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.
LGTM! Thanks for your persistence.
uftrace: Add sub-command specific help
i redirect subcommand help to man pages just like git and perf do.
Fixed: #1316
Signed-off-by: ParkSeungHyeok tmdgur1324@naver.com