mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-07 00:17:47 +00:00
touch: use arggroup for sources
This commit is contained in:
parent
cd4003007f
commit
5ec1bba5e8
1 changed files with 7 additions and 18 deletions
|
@ -13,7 +13,7 @@ pub extern crate filetime;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate uucore;
|
extern crate uucore;
|
||||||
|
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg, ArgGroup};
|
||||||
use filetime::*;
|
use filetime::*;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
|
@ -129,6 +129,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.min_values(1),
|
.min_values(1),
|
||||||
)
|
)
|
||||||
|
.group(ArgGroup::with_name("sources").args(&[
|
||||||
|
options::sources::CURRENT,
|
||||||
|
options::sources::DATE,
|
||||||
|
options::sources::REFERENCE,
|
||||||
|
]))
|
||||||
.get_matches_from(args);
|
.get_matches_from(args);
|
||||||
|
|
||||||
let files: Vec<String> = matches
|
let files: Vec<String> = matches
|
||||||
|
@ -136,19 +141,6 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
.map(|v| v.map(ToString::to_string).collect())
|
.map(|v| v.map(ToString::to_string).collect())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
if matches.is_present(options::sources::DATE)
|
|
||||||
&& (matches.is_present(options::sources::REFERENCE)
|
|
||||||
|| matches.is_present(options::sources::CURRENT))
|
|
||||||
|| matches.is_present(options::sources::REFERENCE)
|
|
||||||
&& (matches.is_present(options::sources::DATE)
|
|
||||||
|| matches.is_present(options::sources::CURRENT))
|
|
||||||
|| matches.is_present(options::sources::CURRENT)
|
|
||||||
&& (matches.is_present(options::sources::DATE)
|
|
||||||
|| matches.is_present(options::sources::REFERENCE))
|
|
||||||
{
|
|
||||||
panic!("Invalid options: cannot specify reference time from more than one source");
|
|
||||||
}
|
|
||||||
|
|
||||||
let (mut atime, mut mtime) = if matches.is_present(options::sources::REFERENCE) {
|
let (mut atime, mut mtime) = if matches.is_present(options::sources::REFERENCE) {
|
||||||
stat(
|
stat(
|
||||||
&matches.value_of(options::sources::REFERENCE).unwrap()[..],
|
&matches.value_of(options::sources::REFERENCE).unwrap()[..],
|
||||||
|
@ -188,10 +180,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Minor optimization: if no reference time was specified, we're done.
|
// Minor optimization: if no reference time was specified, we're done.
|
||||||
if !(matches.is_present(options::sources::DATE)
|
if !matches.is_present("sources") {
|
||||||
|| matches.is_present(options::sources::REFERENCE)
|
|
||||||
|| matches.is_present(options::sources::CURRENT))
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue