-
Notifications
You must be signed in to change notification settings - Fork 251
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
Predefined various timestamp formats #321
Conversation
2d2d3a3
to
8ee7a8a
Compare
src/fping.c
Outdated
@@ -2992,6 +3036,7 @@ void usage(int is_error) | |||
fprintf(out, " -C, --vcount=N same as -c, report results (not stats) in verbose format\n"); | |||
fprintf(out, " -d, --rdns show targets by name (force reverse-DNS lookup)\n"); | |||
fprintf(out, " -D, --timestamp print timestamp before each output line\n"); | |||
fprintf(out, " --timestamp-format=FORMAT show timestamp using the given format (-D are required): [ctime|iso|reltime]\n"); |
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.
-D is required
or -D required
to shorten it.
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.
To shorten it a bit more:
show timestamp in the given format (-D required): ctime|iso|reltime\n
So maybe wrapping can be avoided.
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 feedback and the suggestion.
I have adopted the change and hope the rest of the code is also ok
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.
All in all, this looks OK. Please consider my comments, but you do not need to make any changes on my behalf.
Thanks!
ci/test-05-options-c-e.pl
Outdated
@@ -1,6 +1,6 @@ | |||
#!/usr/bin/perl -w | |||
|
|||
use Test::Command tests => 33; | |||
use Test::Command tests => 42; |
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.
Please consider adding two error test cases for the new option:
- omitting the format name, and
- using an unsupported format name.
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 have add two negativ test --timestamp-format
and --timestamp-format="%Y-%m-%d %H:%M:%S"
both ending in function usage() with exit code 1
src/fping.c
Outdated
current_time_s = current_time_ns / 1000000000; | ||
local_time = localtime(¤t_time_s); | ||
if(timestamp_format == 1) { | ||
strftime(time_buffer, sizeof(time_buffer), "%c", local_time); |
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.
Before this patch, strftime
is not used in the fping
code. Should configure
check for availability of strftime
?
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.
It's also done
src/fping.c
Outdated
if(timestamp_format >= 1 && timestamp_format <= 3) { | ||
current_time_s = current_time_ns / 1000000000; | ||
local_time = localtime(¤t_time_s); | ||
if(timestamp_format == 1) { |
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'd think this part (i.e., the inner if
) would be more readable using switch
.
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.
The if statement has been completely converted into a switch statement. Many thanks for this feedback.
Switch statement with the default is also better than the old if else.
This way, the default is always used if the function is passed incorrectly
Please also consider adding a description to the man page, i.e., |
I am not so sure any more, especially regarding
Perhaps we should leave out And a nit: both (As another example, GNU date has two quite similar "named" time format options where the output differs mainly with the character between date and time, either a space or a |
The formats are not perfect. I have now turned reltime into rfc3339, even with the knowledge that the format may not be one hundred percent perfect. |
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 adjustments, this looks good. :-)
We haven't talked about the process for merging pull requests yet. I would be willing to merge this pull request next weekend, unless there are objections. Is that OK? |
The last github merges were probably done with rebase. All my pull requests are always based on the current state of develop and I always try to do a rebase on all branches in my repository when the develop branch changes here. So I would prefer rebase and merge |
Ah, I see, that is one of the options shown when clicking the arrow next to Merge pull request. I think I (slightly) prefer that option too, because automatic merge commits add some noise, but only little information. I'll go ahead and do that, thanks! (For the record: I do not like the Squash and merge option, I prefer to keep the individual commits.) |
This extension allows you to change the format of the timestamp when using
fping -D -l 127.0.0.1
.Example:
fping -D -l --timestamp-format=ctime 127.0.0.1
Issue: #310