Skip to content

Commit cc101fa

Browse files
RenjiSannsylvestre
authored andcommitted
date: Prevent -d|-f|-r to be used with -s
1 parent 445abbe commit cc101fa

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/uu/date/src/date.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,17 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
185185
DateSource::Now
186186
};
187187

188-
let set_to = match matches.get_one::<String>(OPT_SET).map(parse_date) {
188+
let set_option = matches.get_one::<String>(OPT_SET);
189+
190+
// Before parsing an eventual OPT_SET, check if it can't be present.
191+
if !matches!(date_source, DateSource::Now) && set_option.is_some() {
192+
return Err(USimpleError::new(
193+
1,
194+
"the options to print and set the time may not be used together",
195+
));
196+
}
197+
198+
let set_to = match set_option.map(parse_date) {
189199
None => None,
190200
Some(Err((input, _err))) => {
191201
return Err(USimpleError::new(

0 commit comments

Comments
 (0)