Skip to content

feat: add customizable uptime display with multiple time units#102

Merged
joncrangle merged 1 commit intojoncrangle:mainfrom
NightWatcher314:main
Sep 22, 2025
Merged

feat: add customizable uptime display with multiple time units#102
joncrangle merged 1 commit intojoncrangle:mainfrom
NightWatcher314:main

Conversation

@NightWatcher314
Copy link
Contributor

@NightWatcher314 NightWatcher314 commented Sep 18, 2025

Summary

  • Add new uptime module with flexible time unit support (week, day, hour, min, sec)
  • Implement intelligent unit sorting and carry-over logic
  • Move uptime from system stats to dedicated --uptime flag
  • Support custom unit combinations (e.g., --uptime day min)
  • Update CLI to include --uptime flag with unit validation
  • Update README with correct uptime usage examples

Changes

  • Created new src/stats/uptime.rs module with customizable time unit display
  • Modified CLI to add --uptime flag with proper validation
  • Updated system stats to remove uptime (now handled separately)
  • Fixed README examples to show correct space-separated flag syntax

Test plan

  • Verify --uptime flag works with various unit combinations
  • Confirm README examples match actual CLI behavior
  • Test backward compatibility with existing functionality

@NightWatcher314 NightWatcher314 force-pushed the main branch 2 times, most recently from b14a8f2 to 3b1a010 Compare September 18, 2025 23:03
@joncrangle joncrangle requested a review from Copilot September 19, 2025 12:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a customizable uptime display system that allows users to specify which time units to show (week, day, hour, min, sec) and moves uptime functionality from system stats to a dedicated --uptime flag.

  • Created a new uptime module with flexible time unit support and intelligent carry-over logic
  • Added --uptime CLI flag with proper validation and removed uptime from system stats
  • Updated documentation to reflect the new uptime usage patterns

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/stats/uptime.rs New module implementing customizable uptime display with multiple time units
src/stats/system.rs Removed uptime handling from system stats
src/stats/mod.rs Added uptime module export
src/main.rs Integrated new uptime flag handling and removed old uptime logic
src/cli.rs Added --uptime flag and removed uptime from system flags
README.md Updated documentation with new uptime usage examples

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

src/cli.rs Outdated
}

pub fn all_uptime_flags() -> Vec<&'static str> {
vec!["day", "hour", "min", "sec", "week"]
Copy link

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The uptime flags are not sorted in the same order as TIME_UNITS in uptime.rs (week, day, hour, min, sec). This inconsistency could be confusing. Consider ordering them consistently, either largest-to-smallest or alphabetically.

Suggested change
vec!["day", "hour", "min", "sec", "week"]
vec!["week", "day", "hour", "min", "sec"]

Copilot uses AI. Check for mistakes.
Comment on lines +44 to +50
let mut flags_vec: Vec<&str> = flags.iter().copied().collect();
flags_vec.sort_by_key(|&flag| {
TIME_UNITS
.iter()
.position(|u| u.name == flag)
.unwrap_or(usize::MAX)
});
Copy link

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using unwrap_or(usize::MAX) could place invalid flags at the end of the sorted list instead of handling them properly. Invalid flags should be filtered out or cause an error, as they won't match any TIME_UNITS entry and will be silently ignored in the following loop.

Copilot uses AI. Check for mistakes.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use the following to filter out invalid flags:

    let sorted_flags: Vec<&str> = if flags.is_empty() {
        TIME_UNITS.iter().map(|u| u.name).collect()
    } else {
        let mut flags_vec: Vec<&str> = flags
            .iter()
            .copied()
            .filter(|&flag| TIME_UNITS.iter().any(|u| u.name == flag))
            .collect();

        flags_vec.sort_by_key(|&flag| TIME_UNITS.iter().position(|u| u.name == flag).unwrap());
        flags_vec
    };

@joncrangle
Copy link
Owner

Thanks for the PR. I've tested and works great. Please address the two review comments and I'll merge. Please run cargo fmt and cargo clippy to make sure it will pass CI.

@NightWatcher314
Copy link
Contributor Author

Apologies for the delayed response. I’ve been quite busy the past couple of days and unfortunately missed replying to this PR. I’ll now make the necessary changes as per your suggestions and get them updated shortly.

- Add support for customizable uptime display units (week, day, hour, min, sec)
- Allow users to specify which time units to display via CLI flags
- Implement intelligent time unit conversion and formatting
- Update README with correct usage examples for --uptime flag
@joncrangle joncrangle merged commit ae65117 into joncrangle:main Sep 22, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants