last: fix some hostnames are not shown properly with --hostname option issue 212#246
Conversation
|
could you please add a test to make sure we don't regress? thanks |
There was a problem hiding this comment.
PR Overview
This PR addresses an issue where the hostname is not displayed properly when using the --hostname option by refactoring the formatting logic.
- Reformats the time and end time output by replacing a computed width with fixed-width fields.
- Moves the hostname output to a separate conditional block to ensure it is printed correctly when required.
Reviewed Changes
| File | Description |
|---|---|
| src/uu/last/src/platform/unix.rs | Adjusts formatting logic for time, end time, and hostname output. |
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (2)
src/uu/last/src/platform/unix.rs:525
- [nitpick] Consider replacing the magic number 12 with a named constant for clarity and maintainability.
write!(buf, " {time:<12}").unwrap_or_default();
src/uu/last/src/platform/unix.rs:526
- [nitpick] Consider replacing the magic number 18 with a named constant for clarity and maintainability.
write!(buf, " {end_time_delta:<18}").unwrap_or_default();
|
Hello, the last command doesn't work in mac OS and as I understand cannot work per this post: Maybe better to restrict the last command to the (true) *Nix platform? Let's me know. |
|
Hello @sylvestre, |
|
Hello, |
|
@LionelMeli yes, doing it like in #234 is fine. |
tests/by-util/test_last.rs
Outdated
| let ouput = String::from_utf8(result.stdout().to_vec()) | ||
| .unwrap_or("Failed to convert output to string".to_string()); | ||
| let mut output_result: Vec<&str> = ouput.split('\n').collect(); | ||
| // Remove the last 3 lines to compare easier with the expected output (so without the information about the begin of file) | ||
| output_result.truncate(output_result.len() - 3); |
There was a problem hiding this comment.
I think you can simplify this code to make the intent clearer with something like:
| let ouput = String::from_utf8(result.stdout().to_vec()) | |
| .unwrap_or("Failed to convert output to string".to_string()); | |
| let mut output_result: Vec<&str> = ouput.split('\n').collect(); | |
| // Remove the last 3 lines to compare easier with the expected output (so without the information about the begin of file) | |
| output_result.truncate(output_result.len() - 3); | |
| let output_result: Vec<_> = result.stdout_str().lines().take(3).collect(); |
src/uu/last/src/platform/unix.rs
Outdated
| write!(buf, " {time:<time_size$}").unwrap_or_default(); | ||
| write!(buf, " {end_time:<8}").unwrap_or_default(); | ||
| if self.time_format != "notime" { | ||
| let time_ftm = 12; |
There was a problem hiding this comment.
I think there is a typo and it should be fmt instead of ftm.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #246 +/- ##
===========================
===========================
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for your PR! |
No description provided.