Skip to content

Replace humantime dependency for jiff #382

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 48 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions crates/trycmd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ rayon = "1.5.1"

serde = { version = "1.0", features = ["derive"] }
shlex = "1.1.0"
humantime = "2"
humantime-serde = "1"
jiff = { version = "0.2.4", default-features = false }
toml_edit = { version = "0.22.13", features = ["serde"] }
escargot = { version = "0.5.13", optional = true }

Expand Down
7 changes: 5 additions & 2 deletions crates/trycmd/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::eprintln;
#[cfg(not(feature = "color"))]
use std::io::stderr;

use jiff::SignedDuration;
use rayon::prelude::*;
use snapbox::data::DataFormat;
use snapbox::dir::FileType;
Expand Down Expand Up @@ -68,10 +69,11 @@ impl Runner {
status.spawn.status.summary(),
);
if let Some(duration) = status.duration {
let duration = SignedDuration::try_from(duration).unwrap();
let _ = write!(
stderr,
" {}",
palette.hint(humantime::format_duration(duration)),
palette.hint(format!("{duration:#}")),
);
}
let _ = writeln!(stderr);
Expand All @@ -90,10 +92,11 @@ impl Runner {
palette.error("failed"),
);
if let Some(duration) = status.duration {
let duration = SignedDuration::try_from(duration).unwrap();
let _ = write!(
stderr,
" {}",
palette.hint(humantime::format_duration(duration)),
palette.hint(format!("{duration:#}")),
);
}
let _ = writeln!(stderr);
Expand Down
22 changes: 21 additions & 1 deletion crates/trycmd/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,32 @@ pub struct OneShot {
#[serde(default)]
pub(crate) binary: bool,
#[serde(default)]
#[serde(deserialize_with = "humantime_serde::deserialize")]
#[serde(deserialize_with = "deserialize_jiff_duration")]
pub(crate) timeout: Option<std::time::Duration>,
#[serde(default)]
pub(crate) fs: Filesystem,
}

fn deserialize_jiff_duration<'de, D>(
deserializer: D,
) -> Result<Option<std::time::Duration>, D::Error>
where
D: serde::Deserializer<'de>,
{
use serde::de::Deserialize;

let buf = String::deserialize(deserializer)?;

if buf.is_empty() {
return Ok(None);
}
Comment on lines +662 to +666
Copy link
Contributor

Choose a reason for hiding this comment

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

Was an empty string previously supported?

Copy link
Author

Choose a reason for hiding this comment

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

Will look into humantime implementation

Choose a reason for hiding this comment

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

humantime::parse_duration reports an error for empty strings (as Jiff does).


buf.parse::<jiff::SignedDuration>()
.and_then(std::time::Duration::try_from)
.map(Some)
.map_err(serde::de::Error::custom)
}

impl OneShot {
fn parse_toml(s: &str) -> Result<Self, crate::Error> {
toml_edit::de::from_str(s).map_err(|e| e.to_string().into())
Expand Down