mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 02:08:09 +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]
|
||||
extern crate uucore;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use clap::{App, Arg, ArgGroup};
|
||||
use filetime::*;
|
||||
use std::fs::{self, File};
|
||||
use std::io::Error;
|
||||
|
@ -129,6 +129,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
.takes_value(true)
|
||||
.min_values(1),
|
||||
)
|
||||
.group(ArgGroup::with_name("sources").args(&[
|
||||
options::sources::CURRENT,
|
||||
options::sources::DATE,
|
||||
options::sources::REFERENCE,
|
||||
]))
|
||||
.get_matches_from(args);
|
||||
|
||||
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())
|
||||
.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) {
|
||||
stat(
|
||||
&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.
|
||||
if !(matches.is_present(options::sources::DATE)
|
||||
|| matches.is_present(options::sources::REFERENCE)
|
||||
|| matches.is_present(options::sources::CURRENT))
|
||||
{
|
||||
if !matches.is_present("sources") {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue