Skip to content

Commit 330d9f0

Browse files
committed
fix: improve duration formatting in interactive mode
- Format duration with appropriate precision (ms, seconds, or minutes) - Remove excessive nanosecond precision (9 decimal places) - Display human-readable time format based on duration length - Update CI workflow for better musl tools installation
1 parent 1989af2 commit 330d9f0

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

.github/workflows/release.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,34 @@ jobs:
3434
artifact_name: bssh
3535
asset_name: bssh-linux-x86_64
3636
archive_ext: ".tar.gz"
37-
protoc_platform: linux-x86_64
3837

3938
# Linux x86_64 (musl - static)
4039
- target: x86_64-unknown-linux-musl
4140
os: ubuntu-latest
4241
artifact_name: bssh
4342
asset_name: bssh-linux-x86_64-musl
4443
archive_ext: ".tar.gz"
45-
protoc_platform: linux-x86_64
4644

4745
# Linux ARM64 (glibc)
4846
- target: aarch64-unknown-linux-gnu
4947
os: ubuntu-22.04-arm
5048
artifact_name: bssh
5149
asset_name: bssh-linux-aarch64
5250
archive_ext: ".tar.gz"
53-
protoc_platform: linux-aarch_64
5451

5552
# Linux ARM64 (musl - static)
5653
- target: aarch64-unknown-linux-musl
5754
os: ubuntu-24.04-arm
5855
artifact_name: bssh
5956
asset_name: bssh-linux-aarch64-musl
6057
archive_ext: ".tar.gz"
61-
protoc_platform: linux-aarch_64
6258

6359
# macOS ARM64
6460
- target: aarch64-apple-darwin
6561
os: macos-14
6662
artifact_name: bssh
6763
asset_name: bssh-macos-aarch64
6864
archive_ext: ".zip"
69-
protoc_platform: osx-aarch_64
7065

7166
env:
7267
BIN_NAME: bssh
@@ -102,8 +97,8 @@ jobs:
10297
run: rustup target add ${{ matrix.target }}
10398

10499
# 5) Install musl tools only for aarch64 musl builds
105-
- name: Install ARM64 musl tools (Linux aarch64 musl only)
106-
if: matrix.target == 'aarch64-unknown-linux-musl'
100+
- name: Install musl tools (Linux musl only)
101+
if: contains(matrix.target, 'musl')
107102
run: |
108103
sudo apt update
109104
sudo apt install -y musl-tools

src/main.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use anyhow::Result;
1616
use clap::Parser;
17+
use std::time::Duration;
1718

1819
use bssh::{
1920
cli::{Cli, Commands},
@@ -31,6 +32,32 @@ use bssh::{
3132
utils::init_logging,
3233
};
3334

35+
/// Format a Duration into a human-readable string
36+
fn format_duration(duration: Duration) -> String {
37+
let total_seconds = duration.as_secs_f64();
38+
39+
if total_seconds < 1.0 {
40+
// Less than 1 second: show in milliseconds
41+
format!("{:.1} ms", duration.as_secs_f64() * 1000.0)
42+
} else if total_seconds < 60.0 {
43+
// Less than 1 minute: show in seconds with 2 decimal places
44+
format!("{total_seconds:.2} s")
45+
} else {
46+
// 1 minute or more: show in minutes and seconds
47+
let minutes = duration.as_secs() / 60;
48+
let seconds = duration.as_secs() % 60;
49+
let millis = duration.subsec_millis();
50+
51+
if seconds == 0 {
52+
format!("{minutes}m")
53+
} else if millis > 0 {
54+
format!("{minutes}m {seconds}.{millis:03}s")
55+
} else {
56+
format!("{minutes}m {seconds}s")
57+
}
58+
}
59+
}
60+
3461
#[tokio::main]
3562
async fn main() -> Result<()> {
3663
let cli = Cli::parse();
@@ -134,7 +161,7 @@ async fn main() -> Result<()> {
134161
};
135162
let result = interactive_cmd.execute().await?;
136163
println!("\nInteractive session ended.");
137-
println!("Duration: {:?}", result.duration);
164+
println!("Duration: {}", format_duration(result.duration));
138165
println!("Commands executed: {}", result.commands_executed);
139166
println!("Nodes connected: {}", result.nodes_connected);
140167
Ok(())

0 commit comments

Comments
 (0)