Skip to content

Commit

Permalink
Merge pull request #4927 from cakebaker/bump_fundu_and_fix_compile_er…
Browse files Browse the repository at this point in the history
…rors

Bump fundu to 1.0.0 and fix compile errors
  • Loading branch information
sylvestre committed Jun 10, 2023
2 parents 7b3467f + b6c02c1 commit 63b84fe
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ filetime = "0.2"
fnv = "1.0.7"
fs_extra = "1.3.0"
fts-sys = "0.2"
fundu = "0.5.1"
fundu = "1.0.0"
gcd = "2.3"
glob = "0.3.1"
half = "2.2"
Expand Down
8 changes: 5 additions & 3 deletions src/uu/sleep/src/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use uucore::{
};

use clap::{crate_version, Arg, ArgAction, Command};
use fundu::{self, DurationParser, ParseError};
use fundu::{self, DurationParser, ParseError, SaturatingInto};

static ABOUT: &str = help_about!("sleep.md");
const USAGE: &str = help_usage!("sleep.md");
Expand Down Expand Up @@ -63,7 +63,7 @@ pub fn uu_app() -> Command {
fn sleep(args: &[&str]) -> UResult<()> {
let mut arg_error = false;

use fundu::TimeUnit::*;
use fundu::TimeUnit::{Day, Hour, Minute, Second};
let parser = DurationParser::with_time_units(&[Second, Minute, Hour, Day]);

let sleep_dur = args
Expand Down Expand Up @@ -91,7 +91,9 @@ fn sleep(args: &[&str]) -> UResult<()> {
None
}
})
.fold(Duration::ZERO, |acc, n| acc.saturating_add(n));
.fold(Duration::ZERO, |acc, n| {
acc.saturating_add(SaturatingInto::<std::time::Duration>::saturating_into(n))
});

if arg_error {
return Err(UUsageError::new(1, ""));
Expand Down
17 changes: 10 additions & 7 deletions src/uu/tail/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::paths::Input;
use crate::{parse, platform, Quotable};
use clap::crate_version;
use clap::{Arg, ArgAction, ArgMatches, Command};
use fundu::DurationParser;
use fundu::{DurationParser, SaturatingInto};
use is_terminal::IsTerminal;
use same_file::Handle;
use std::collections::VecDeque;
Expand Down Expand Up @@ -235,12 +235,15 @@ impl Settings {
// `DURATION::MAX` or `infinity` was given
// * not applied here but it supports customizable time units and provides better error
// messages
settings.sleep_sec =
DurationParser::without_time_units()
.parse(source)
.map_err(|_| {
UUsageError::new(1, format!("invalid number of seconds: '{source}'"))
})?;
settings.sleep_sec = match DurationParser::without_time_units().parse(source) {
Ok(duration) => SaturatingInto::<std::time::Duration>::saturating_into(duration),
Err(_) => {
return Err(UUsageError::new(
1,
format!("invalid number of seconds: '{source}'"),
))
}
}
}

if let Some(s) = matches.get_one::<String>(options::MAX_UNCHANGED_STATS) {
Expand Down

0 comments on commit 63b84fe

Please sign in to comment.