1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

tail: clean up some small things in input parsing

This commit is contained in:
Terts Diepraam 2023-07-03 13:20:48 +02:00
parent ae60045f3f
commit 5a667db43d
2 changed files with 5 additions and 9 deletions

View file

@ -7,7 +7,7 @@
use crate::paths::Input; use crate::paths::Input;
use crate::{parse, platform, Quotable}; use crate::{parse, platform, Quotable};
use clap::crate_version; use clap::{crate_version, value_parser};
use clap::{Arg, ArgAction, ArgMatches, Command}; use clap::{Arg, ArgAction, ArgMatches, Command};
use fundu::DurationParser; use fundu::DurationParser;
use is_terminal::IsTerminal; use is_terminal::IsTerminal;
@ -283,7 +283,7 @@ impl Settings {
} }
settings.inputs = matches settings.inputs = matches
.get_raw(options::ARG_FILES) .get_many::<OsString>(options::ARG_FILES)
.map(|v| v.map(Input::from).collect()) .map(|v| v.map(Input::from).collect())
.unwrap_or_else(|| vec![Input::default()]); .unwrap_or_else(|| vec![Input::default()]);
@ -584,6 +584,7 @@ pub fn uu_app() -> Command {
Arg::new(options::ARG_FILES) Arg::new(options::ARG_FILES)
.action(ArgAction::Append) .action(ArgAction::Append)
.num_args(1..) .num_args(1..)
.value_parser(value_parser!(OsString))
.value_hint(clap::ValueHint::FilePath), .value_hint(clap::ValueHint::FilePath),
) )
} }

View file

@ -10,10 +10,7 @@ use std::ffi::OsStr;
use std::fs::{File, Metadata}; use std::fs::{File, Metadata};
use std::io::{Seek, SeekFrom}; use std::io::{Seek, SeekFrom};
#[cfg(unix)] #[cfg(unix)]
use std::os::unix::{ use std::os::unix::fs::{FileTypeExt, MetadataExt};
fs::{FileTypeExt, MetadataExt},
prelude::OsStrExt,
};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use uucore::error::UResult; use uucore::error::UResult;
@ -26,9 +23,7 @@ pub enum InputKind {
#[cfg(unix)] #[cfg(unix)]
impl From<&OsStr> for InputKind { impl From<&OsStr> for InputKind {
fn from(value: &OsStr) -> Self { fn from(value: &OsStr) -> Self {
const DASH: [u8; 1] = [b'-']; if value == OsStr::new("-") {
if value.as_bytes() == DASH {
Self::Stdin Self::Stdin
} else { } else {
Self::File(PathBuf::from(value)) Self::File(PathBuf::from(value))