Skip to content

Commit

Permalink
date: Prevent -d|-f|-r to be used with -s
Browse files Browse the repository at this point in the history
  • Loading branch information
RenjiSann committed Jul 11, 2024
1 parent 1428f78 commit 7906ff7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/uu/date/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,17 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
DateSource::Now
};

let set_to = match matches.get_one::<String>(OPT_SET).map(parse_date) {
let set_option = matches.get_one::<String>(OPT_SET);

// Before parsing an eventual OPT_SET, check if it can't be present.
if !matches!(date_source, DateSource::Now) && set_option.is_some() {
return Err(USimpleError::new(

Check warning on line 192 in src/uu/date/src/date.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/date/src/date.rs#L192

Added line #L192 was not covered by tests
1,
"the options to print and set the time may not be used together",
));
}

let set_to = match set_option.map(parse_date) {
None => None,
Some(Err((input, _err))) => {
return Err(USimpleError::new(
Expand Down

0 comments on commit 7906ff7

Please sign in to comment.